popo63301

popo63301

Add a favicon to a Phoenix app

What is the proper way to add a favicon to a Phoenix app ?

Marked As Solved

idi527

idi527

:waving_hand:

If you are using the default setup, then replacing assets/static/favicon.ico with your own favicon.ico should be enough.


For adding the bigger sized favicons, you’d also need to include a manifest.json in your static files and serve it with Plug.Static in endpoint.ex:

plug Plug.Static,
    at: "/",
    from: :your_app,
    gzip: true,
-   only: ~w(css fonts images js lib favicon.ico robots.txt)
+   only: ~w(css fonts images js lib favicon.ico apple-touch-icon.png favicon-32x32.png favicon-16x16.png manifest.json robots.txt)

You’d also need to update your templates/layout/app.html.eex to point the browser to that manifest:

+ <link rel="apple-touch-icon" sizes="180x180" href="/apple-touch-icon.png">
+ <link rel="icon" type="image/png" sizes="32x32" href="/favicon-32x32.png">
+ <link rel="icon" type="image/png" sizes="16x16" href="/favicon-16x16.png">
+ <link rel="manifest" href="/manifest.json">
21
Post #2

Also Liked

f0rest8

f0rest8

Another resource that seems to be great for this is:

They include a favicon checker after you finish generating everything and it includes support for Windows 8 and 10 tiles too. I renamed the site.manifest file as manifest.json per @idi527 's post.

Raf

Raf

Just wanted to add a note to this, because the favicon was working fine locally, but failing to load (with a 404) after deployment.

Locally, Phoenix will always load favicon.ico, but after bundling, it tries to load something like favicon-41a4deef9b2b06219597139b6e017760.ico?vsn=d. I debugged the deployed docker image and the file was definitely there.

It took me some time to realize that the problem was with the static_paths I was allowing, which included favicon.ico but not favicon-41a4deef9b2b06219597139b6e017760.ico.

So doing what @karlosmid suggests make sense and did fix the problem.

I’m now just wondering if that shouldn’t be the default for a new phoenix app…

Last Post!

Raf

Raf

Just wanted to add a note to this, because the favicon was working fine locally, but failing to load (with a 404) after deployment.

Locally, Phoenix will always load favicon.ico, but after bundling, it tries to load something like favicon-41a4deef9b2b06219597139b6e017760.ico?vsn=d. I debugged the deployed docker image and the file was definitely there.

It took me some time to realize that the problem was with the static_paths I was allowing, which included favicon.ico but not favicon-41a4deef9b2b06219597139b6e017760.ico.

So doing what @karlosmid suggests make sense and did fix the problem.

I’m now just wondering if that shouldn’t be the default for a new phoenix app…

Where Next?

Popular in Questions Top

rms.mrcs
Hi, I need to transform a list of numbers into a map where the keys are the indexes and the values are the original values of the list. ...
New
jononomo
I am trying to figure out how Mix knows whether the environment is test, dev, or prod – where is this set? Thanks.
New
Qqwy
Original source of discussion: This topic on the Pragmatic Programmers’ Functional Web Development with Elixir, OTP, and Phoenix forum. ...
New
Lily
In templates/appointment/index.html.eex: &lt;%= for appointment &lt;- @appointments do %&gt; &lt;tr&gt; &lt;td&gt;&lt;%= appoi...
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
Harrisonl
We have an ECS cluster with 4 services, where each task joins a single cluster, via discovery ECS discovery service. Currently when I de...
New
jason.o
In the code below, if the create action is not set to accept “extra_key” as an input, it errors out with a message shown above. Is there ...
New

Other popular topics Top

electic
Hi, I am new to Elixir. I am trying to use the DateTime component to insert a date into MySQL however the there seems to be no way to fo...
New
stefanchrobot
What’s the safe way to decode a JSON string into a struct? I want to avoid calling String.to_atom. Jason.decode can give me a map with st...
New
Darmani72
If I have a post route which an argument: post /my_post_route/:my_param1, MyController.my_post_handler How would get the post params ...
New
joeerl
Hello again - after a longish gap I’ve decided I really must dig into Elixir and see what’s been happening here - so I have a few questio...
New
gshaw
What is the idiomatic way of matching for not nil in Elixir? E.g., First way: defp halt_if_not_signed_in(conn, signed_in_account) when...
New
AstonJ
Posting this to see if we can make things easier for people to get into Neovim. If you use Neovim and have a favourite distro please let ...
New

We're in Beta

About us Mission Statement