MatijaL

MatijaL

How to use versioned file in my template?

Hello,

I have icons.svg file which contains svg symbols. In my template I use it like this with a verified route:

<svg>
   <use xlink:href={ ~p"/images/icons.svg#arrow" }></use>
</svg>

This line of code always calls for icons.svg file, but in production, this file gets versioned to something like icons-83f2a9a213b74424476fb160bbabaec8.svg?vsn=d.

How do I update verified routes to use versioned filename instead of base icons.svg?

Marked As Solved

psantos

psantos

Maybe Routes.static_path/2 would help.

<svg>
   <use xlink:href={static_path(@conn, "/images/icons.svg") <> "#arrow"}></use>
</svg>

In development static_path/2 will return icons.svg but in production it will return the path to the fingerprinted version.

Also Liked

LostKobrakai

LostKobrakai

Looking at the code it seems the #arrow part means matching with the cache manifest doesn’t work. Caching uses the path as supplied and doesn’t strip fragments from it, which therefore doesn’t match paths on the filesystem, which don’t have fragments to them.

MatijaL

MatijaL

Thank you for giving me the example.

Here’s the code with verified route which works.

<svg>
   <use xlink:href={ ~p"/images/icons.svg" <> "#arrow" }></use>
</svg>

Where Next?

Popular in Questions Top

RisingFromAshes
I’ve read in another post that it may be possible with a router helper - but I couldn’t find an appropriate one, and tbh, I’m still just ...
New
minhajuddin
I have seen a lot of code which picks the first element from a list using Enum.at(0) instead of List.first. Is there a reason why people ...
New
joaquinalcerro
Hi there, I am working with Ecto-Postgresql and I need to call all of the records from a specific table but the table has 40,000 records...
New
Qqwy
Original source of discussion: This topic on the Pragmatic Programmers’ Functional Web Development with Elixir, OTP, and Phoenix forum. ...
New
hariharasudhan94
I would like to know what is the best IDE for elixir development?
New
skosch
To my knowledge, put_in, Map.update etc. all have the one limitation of not automatically creating intermediate keys when needed (for exa...
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
beno
I will often find my self writing things similar to: case some_value do nil -&gt; something() "" -&gt; something() _ -&gt; somethi...
New
belgoros
I’m not a pro in using Regex and can’t figure out why the following behaviour happens, especially if we take into account the difference ...
New
Patoshizzle
After calling mix ecto.create I get this error: 17:00:32.162 [error] GenServer #PID&lt;0.412.0&gt; terminating ** (Postgrex.Error) FATAL...
New

Other popular topics Top

Qqwy
Original source of discussion: This topic on the Pragmatic Programmers’ Functional Web Development with Elixir, OTP, and Phoenix forum. ...
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 54120 245
New
mcarvalho
What is the difference between System.get_env and Application.get_env? For example, what are best practices to use one versus another.
New
ashish173
I am using Ecto timestamps with postgres, I can see the timestamps() use the :naive_dateime but for my use case I wanted to store the ti...
New
jay1
Why is it that the mnesia database isn’t the most preferred database for use in Elixir/Phoenix?
New
sergio_101
I am VERY much an elixir newbie. I have taken one elixir course and one phoenix course on Udemy. During that course, I saw the instructor...
New
bsollish-terakeet
Credo is smart enough to check for (something like) this: assert length(the_list) == 0 with this response: Checking if an enum is empt...
New
vrod
I am using the Starship cross-shell prompt – it seems pretty nice, but I get some errors: [WARN] - (starship::utils): Executing command ...
New
WestKeys
Currently suffering from paralysis by [HTTP client] analysis. This is rather unusual in Elixirland as there tends to be consensus on the ...
New
malloryerik
Hi, this is for people who, like me, have had some friction using .html.heex templates in VSCode. The solution seems to be, in a hyphena...
New

Latest on Elixir Forum

Elixir Forum

We're in Beta

About us Mission Statement