I would like to ask for help to understand why it doesn’t work and what is the correct way of using it?
<%= Routes %>, { Routes } or directly passing “/images/x”?
It was not an upgrade from Phoenix 1.5 but a direct 1.6 install.
I’m still a bit confused but at least it’s working, so I’ll assume I should use always priv/static… right?
I’m not using Phoenix 1.6.6, did you find the solution?
This is a problem, it’s confusing to have things changing and breaking like that specially considering that sometimes the docs don’t mention how to do it.
I guess I’m not going to update Phoenix for a while…
From 1.6.0 the docs say that all other assets, that usually don't have to be preprocessed, go directly to "priv/static".
1.6.1 added the Images, fonts, and external files section, saying that the images are already managed by Phoenix, meaning that it’ll serve the static_path directly from priv/static, and that running mix phx.digest will create digested files for all of the assets in priv/static/images, so your images and fonts are still cache-busted.
Placing all images in priv/static/images manually is the “correct” way as of 1.6 as there is no real difference between an app generated with v1.6.0 or v.1.6.6
So the question is what’s not working for you?
I was also quite confused by the asset changes, especially upgrading from phoenix 1.5.x. This tripped me up, but also didn’t take into account the .gitignore changes to account for the new structure, which only ignores specific assets
pre-1.6
# Since we are building assets from assets/,
# we ignore priv/static. You may want to comment
# this depending on your deployment strategy.
/priv/static/
1.6.x
# Ignore assets that are produced by build tools.
/priv/static/assets/
# Ignore digested assets cache.
/priv/static/cache_manifest.json
Then just moving my files from assets/static to priv/static did the trick.
By the way, using <img src="/images/psi.png" /> directly won’t take advantage of the cache-busting feature of mix phx.digest. (also see the mix_tasks and Runtime configuration docs)
<img src={ Routes.static_path(@conn, "/images/psi.png")} /> will be compiled into something like <img src="/images/psi-eb0a5b9302e8d32828d8a73f137cc8f0.png" /> in production, which lets the browser fetch an updated image as soon as you make a new release instead of waiting until its cache expires. Very important if you’re serving static assets from a CDN or otherwise handling cache-control headers.
The images should be put in assets/images and webpacker (or whatever is used to compile assets) should be putting them in priv/static. If someone is manually editing priv/static…and they have an asset compiler (which they should), these changes will be overwritten.
I have been facing the same issue, coming from Laravel, I thought that as long as the files are in the priv/static directory, it doesn’t matter where you place the images or js and css. I had placed the images , css and js files in priv/static/assets/client but there was an error in the console saying that those files are not found. So After doing research online, I placed the js and css files in the priv/static/assets directory and images in the priv/static/images directory and it worked.
Interesting on the esbuild with Phoenix. I think later versions of Rails are also moving away from Webpacker. (My Rails app is still on Sprockets :(( )
What I was saying is that the priv/static directory is going to be overwritten whenever webpacker compiles. so it’s not safe to put files directly into priv/static ONLY, as you will lose them.