jack
Hello there,
I’m trying to load image assets in heex html code.
I’ve tried the following:
<img src="<%= Routes.static_path(@conn, "/images/psi.png") %>"/>
Compile error: expected closing " for attribute value
<img src={ Routes.static_path(@conn, "/images/psi.png") } />
<img src={ Routes.static_path(@conn, "/psi.png") } />
It compiles but doesn’t render the image and trying to open the image in a new tab it complains:
no route found for GET /psi.png
<img src="/images/psi.png" />
Trying to load the image directly is just the same, no render, no route found.
My endpoint:
plug Plug.Static,
at: "/",
from: :health,
gzip: false,
only: ~w(assets fonts images favicon.ico robots.txt)
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”?
Trending in Questions
I’m working on a project that simulates the bumbl example in the programming phoenix book. It acts almost like an email client. We have a...
New
Hello,
I know there is an approach for handling lists that allows for optimized traversal, but I can’t recall the specific method (somet...
New
Hi everyone,
I am toying with the idea of building a “match maker” for giving personal help to people that wants to start coding.
I sta...
New
Documentation
While reading the Scoped Routes section, I noticed that the documentation currently refers to a problem without explainin...
New
So my question is quite simple and i have found no conclusive answer on forum, google or AI.
Should we use :erlang.float for Integer to ...
New
I recently noticed that Elixir’s Logger defaults its primary log level to :debug when no :logger, :level application configuration is pre...
New
I’m new to elixir and just tried to install the elixirLS extension for VScode(ium) and it is throwing some errors that I would like help ...
New
Other Trending Topics
Edit: 2026 May 15 - This post is archived.
Mob is alive!!
Main docs: mob v0.7.11 — Documentation
A bit of explanation for the slightly c...
New
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
I am happy to introduce the very α version of the new programming language compiled to BEAM.
Welcome Cure.
It has literally three kille...
New
Hi there! We created Gust: A task orchestrator inspired by Airflow.
For those who have never heard about Aiflow, it’s a Python-based wor...
New
Hi everyone!
The first release candidate for the Expert language server project is now available!
We’ve published a press release detai...
New
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #library
- #deployment
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #elixirconf
- #channels
- #exunit
- #discussion
- #code-sync
- #podcasts
- #javascript
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #ai
- #elixirconf-us
- #blog-post
- #elixir-ls
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #elixirconf-eu
- #metaprogramming
- #hex










Showing Posts 1 to 10- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
kokolegorille
Where did You put the image?
Is it an upgrade from Phoenix 1.5?
For the first option, You need to put the file in priv/static/images.
The later use assets/static, and it’s copied to priv/static/
What do You have in priv/static/images?
jack
Thank you!
The image was on assets/static/images/, none of the code snippets worked like copying it to priv/static/.
But I’ve put the image directly in priv/static/images/ and I can now use both:
and
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?
kokolegorille
It’s because Phoenix 1.6 dropped webpack and npm. Now that copy-webpack-plugin is removed, You need to copy manually in priv/static.
This one is better in case You digest your assets for production.
dev-rroslan
phoenix 1.6.6 is different, cannot do the above. Still trying
jack
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…
03juan
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 thestatic_pathdirectly from priv/static, and thatrunning 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/imagesmanually 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.6So 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
.gitignorechanges to account for the new structure, which only ignores specific assetsThen just moving my files from
assets/statictopriv/staticdid the trick.03juan
By the way, using
<img src="/images/psi.png" />directly won’t take advantage of the cache-busting feature ofmix phx.digest. (also see themix_tasksand 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 handlingcache-controlheaders.silverdr
FWIW - I encountered a related problem while migrating to 1.6 where both CSS ans JS were not “statically” served. I had to replace my
/css/app.csswith/assets/app.cssas well as
/js/app.jswith/assets/app.jstrechubet
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.
kokolegorille
You probably mean assets/static/images
It’s not really the asset compiler, it’s copy-webpack-plugin that does this move of files.
Latest versions of Phoenix does not use webpack, but esbuild. It is recommended to do it yourself now and place files in priv/static.
Unless You still use webpack (like I still do)