davejs

davejs

Asset favicon.svg not served in prod

I use an svg favicon in my application.
My application was generated with the command: mix phx.new .

I added a favicon.svg file to assets/static.

In the layout file it is referenced as <link rel="icon" href="<%= Routes.static_path(@conn, "/favicon.svg") %>" />.

In dev mode this works. But when i run phoenix in prod mode the favicon is not served.

To build the assets i executed:

npm run deploy --prefix ./assets
mix phx.digest

This runs without any error and produces the following output:

ls priv/static/
cache_manifest.json                              favicon.svg     js                                              robots.txt
favicon-f518d411df681dc1e8258eb14b218a97.svg     favicon.svg.gz  robots-067185ba27a5d9139b10a759679045bf.txt     robots.txt.gz
favicon-f518d411df681dc1e8258eb14b218a97.svg.gz  images          robots-067185ba27a5d9139b10a759679045bf.txt.gz

In my browser devtools i can see that the favicon should be available here: <link rel="icon" href="/favicon-f518d411df681dc1e8258eb14b218a97.svg?vsn=d">.

But if i call this url nothing is returned.

/favicon.svg works though.

Here a part of endpoint.ex

  plug Plug.Static,
    at: "/",
    from: :typeracer,
    gzip: false,
    only: ~w(css fonts images js favicon.svg robots.txt

Does anyone know how i can make the favicon appear?

Marked As Solved

sfusato

sfusato

Perhaps the Plug.Static explicit :only option is the cause of this. From the docs:

:only - filters which requests to serve. This is useful to avoid file system traversals on every request when this plug is mounted at "/". For example, if only: ["images", "favicon.ico"] is specified, only files in the “images” directory and the “favicon.ico” file will be served

Try to move the file inside a folder specified in the :only option and test like that.

Or, keep the favicon at the root, but move it to :only_matching:

:only_matching - a relaxed version of :only that will serve any request as long as one of the given values matches the given path. For example, only_matching: ["images", "favicon"] will match any request that starts at “images” or “favicon”, be it “/images/foo.png”, “/images-high/foo.png”, “/favicon.ico” or “/favicon-high.ico”. Such matches are useful when serving digested files at the root. Defaults to nil (no filtering).

Also Liked

sfusato

sfusato

Make sure you add the prod env when doing mix phx.digest for production environment:

MIX_ENV=prod mix phx.digest

Where Next?

Popular in Questions Top

vegabook
I’m brand new to Phoenix and I have stripped one of the demo applications to the bone. I just want to get an svg up on the screen. Here i...
New
hariharasudhan94
Lets say I have map like this fetching from my database %{"_id" =&gt; #BSON.ObjectId&lt;58eb1a7a9ad169198c3dXXXX&gt;, "email" =&gt; ...
New
_russellb
I want to try my hand at web scraping. What tools/libraries do I need to use. I’m hoping to turn this into something professional so don’...
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
beno
I will often find my self writing things similar to: case some_value do nil -&gt; something() "" -&gt; something() _ -&gt; somethi...
New
shahryarjb
Hello, I have map which I want to convert it to string like this: the map: %{last_name: "tavakkoli", name: "shahryar"} the string I ne...
New
chokchit
** (DBConnection.ConnectionError) connection not available and request was dropped from queue after 2733ms. You can configure how long re...
New
jerry
Good day to you all. I have been struggling to get a query involving like and ilike to work. Can anyone assist me on this, please? pro...
New
pmjoe
I have a relationship of love and hate with Elixir. Lots of things are just absolutely right, but there are some things that are kind of ...
New
albydarned
Hello all! I am typing this post from my new MacBook Pro with the M1 chip. I’m loving it so far, and will probably use it as my daily dr...
New

Other popular topics Top

KronicDeth
Elixir plugin for JetBrain’s IntelliJ Platform (including Rubymine) This is a plugin that adds support for Elixir to JetBrains IntelliJ...
289 36352 110
New
chrismccord
As promised, the first release candidate of Phoenix 1.3.0 is out! This release focuses on code generators with improved project structure...
New
vonH
When I run the Plug and I recompile I wind up having to use Ctrl C to quit iex and start again. Witht the help of rlwrap I can use the cu...
New
ovidiubadita
Hey all, I discovered Elixir and I love it. I always wanted to learn a functional programming and I intended to go for Haskell, but afte...
New
aadeshere1
I have a another noob question about loop. Since elixir is immutable, while loop is not directly possible. total = 10 while total != 0 ...
New
AstonJ
We’ve put together this wiki for Phoenix LiveView - please feel free to add any info you feel is worth including. What is Phoenix LiveV...
New
gausby
I asked this very same question on twitter and got some interesting feedback, but I thought it would be a good question to ask here as we...
1207 39467 209
New
komlanvi
Hi everyone, I was playing with phoenix liveView but I run into an issue. I have a form and want to validate each input text when the te...
New
jerry
Good day to you all. I have been struggling to get a query involving like and ilike to work. Can anyone assist me on this, please? pro...
New
aesmail
Hello guys, I have finally made it. I created an admin interface for a framework. It’s been on my todo list for years and with the curre...
New

Latest on Elixir Forum

We're in Beta

About us Mission Statement