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
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
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
Popular in Questions
Other popular topics
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #websockets
- #supervisor
- #elixirconf-us
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #metaprogramming
- #security
- #hex










