Loading images and assets in phoenix 1.6.2

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.

1 Like