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

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
vonH
In asking this question I am more interested about the expressiveness of the language itself and less concerned about the availability of...
New
lessless
I believe there are people here who are dealing with CSV files import on the daily basis, and since Excel is a really popular tool there ...
New
openscript
Hello! Sorry for this astonishing simple question, but I’m really stuck. I try to set up the intellij-elixir plugin, but I don’t know ho...
New
Darmani72
If I have a post route which an argument: post /my_post_route/:my_param1, MyController.my_post_handler How would get the post params ...
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
fayddelight
I tried installing elixir 1.11.2 erlang 23.3.4 via asdf in my zsh shell. Enabled the versions locally and globally. When I list them ...
New

Other popular topics Top

hariharasudhan94
I would like to know what is the best IDE for elixir development?
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 54996 245
New
joeerl
Hello again - after a longish gap I’ve decided I really must dig into Elixir and see what’s been happening here - so I have a few questio...
New
shijith.k
I am trying to start a new phoenix project with elixir 1.9, but mix phx.new does not work. It says that ** (Mix) The task "phx.new" could...
New
TunkShif
This post is an instruction guide to help you setup your Neovim for Elixir development from scratch. It includes general information on h...
274 42576 114
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