archimondain

archimondain

Understanding Routes.static_path on javascript files

I have a line like this in my phoenix project :

<script type="text/javascript" 
        src="<%= Routes.static_path(@conn, "/js/myScript.js") %>"></script> 

When I run the project with MIX_ENV=“prod”, the generated html looks like this

<script type="text/javascript" 
        src="/js/myScript-e96060ad8bff62ca8d0fbb42c87d0cb4.js?vsn=d"></script>

I assume Phoenix copys the file /js/myScript.js to /js/myScript-e96060ad8bff62ca8d0fbb42c87d0cb4.js. What is the reason of that ?

Also my issue is that when I commit a new version of myScript.js, it is not taken into account : the same old file myScript-e96060ad8bff62ca8d0fbb42c87d0cb4.js is used instead of being updated. What is the best way to handle that ?

Marked As Solved

LostKobrakai

LostKobrakai

This is done by mix phx.digest. It takes all static files and copies them to an additional file with the checksum as part of the filename. It also creates a json manifest file in the root, which has a list of mappings of paths → files with checksum.

This is done to make things like multiple versions on CDN easier – a.k.a. pages already loaded can still access the old script even after a deploy – as well as have proper cache busting if you deploy a new version, so the new html includes a new filename, which prevents the browser from falling back to cached resources no longer current.

Last Post!

archimondain

archimondain

Well, I have a lot of dependencies, which I think was too much to handle. When I remove them from the directory the command succeeds

Where Next?

Popular in Questions Top

RisingFromAshes
I’ve read in another post that it may be possible with a router helper - but I couldn’t find an appropriate one, and tbh, I’m still just ...
New
hariharasudhan94
Lets say I have map like this fetching from my database %{"_id" =&gt; #BSON.ObjectId&lt;58eb1a7a9ad169198c3dXXXX&gt;, "email" =&gt; ...
New
lastday4you
I wanted to check elixir version in phoenix because i found that my elixir is 1.5 but when i use Enum.chunk_by it said the function is un...
New
ashish173
I am using Ecto timestamps with postgres, I can see the timestamps() use the :naive_dateime but for my use case I wanted to store the ti...
New
stefanchrobot
What’s the safe way to decode a JSON string into a struct? I want to avoid calling String.to_atom. Jason.decode can give me a map with st...
New
fireproofsocks
Forgive me if this is obvious, but how does one delete a database record WITHOUT selecting it first? Ecto.Repo — Ecto v3.14.0 has exampl...
New
bsollish-terakeet
Credo is smart enough to check for (something like) this: assert length(the_list) == 0 with this response: Checking if an enum is empt...
New

Other popular topics Top

rms.mrcs
Hi, I need to transform a list of numbers into a map where the keys are the indexes and the values are the original values of the list. ...
New
minhajuddin
I have seen a lot of code which picks the first element from a list using Enum.at(0) instead of List.first. Is there a reason why people ...
New
vonH
In asking this question I am more interested about the expressiveness of the language itself and less concerned about the availability of...
New
axelson
This post is a wiki (feel free to hit the edit button near the bottom right of this post to add your own changes!) This post collects co...
239 49134 226
New
sergio_101
I am VERY much an elixir newbie. I have taken one elixir course and one phoenix course on Udemy. During that course, I saw the instructor...
New
jason.o
In the code below, if the create action is not set to accept “extra_key” as an input, it errors out with a message shown above. Is there ...
New

We're in Beta

About us Mission Statement