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

hariharasudhan94
Lets say I have map like this fetching from my database %{"_id" =&gt; #BSON.ObjectId&lt;58eb1a7a9ad169198c3dXXXX&gt;, "email" =&gt; ...
New
dokuzbir
I want to highlight html closing tags when i click a html tag. That works in .html files but doesnt work for html.eex templates. How can...
New
gshaw
What is the idiomatic way of matching for not nil in Elixir? E.g., First way: defp halt_if_not_signed_in(conn, signed_in_account) when...
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
stefanluptak
Hello everybody, usually, I use a 29" ultra-wide monitor for VSCode which can easily accomodate explorer (files panel) + file with code ...
New
freewebwithme
Using vs code and installed ElixirLS: support and debugger. And I got an error popped up on start up says Failed to run ‘elixir’ comma...
New
vrod
I am using the Starship cross-shell prompt – it seems pretty nice, but I get some errors: [WARN] - (starship::utils): Executing command ...
New

Other popular topics Top

vonH
When I run the Plug and I recompile I wind up having to use Ctrl C to quit iex and start again. Witht the help of rlwrap I can use the cu...
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
JakeBecker
TL;DR: I’ve just released an implementation of Microsoft’s IDE-independent Language Server Protocol for Elixir. It adds language support ...
1144 55125 245
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
albydarned
Hello all! I am typing this post from my new MacBook Pro with the M1 chip. I’m loving it so far, and will probably use it as my daily dr...
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