Skip to content

Instantly share code, notes, and snippets.

@ptz0n
Last active January 2, 2019 13:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ptz0n/1610bb28512c94b53ef3a017f9bae385 to your computer and use it in GitHub Desktop.
Save ptz0n/1610bb28512c94b53ef3a017f9bae385 to your computer and use it in GitHub Desktop.
Serve favicons to all clients

There is a lot of files needed to make all clients happy and show a nice favicon. This note make things a bit simpler by having a set of sizes ready and rewriting request paths.

  1. Make sure you have these sizes available, square works best:
16.png
32.png
36.png
48.png
57.png
60.png
70.png
72.png
76.png
96.png
114.png
120.png
144.png
150.png
152.png
180.png
192.png
194.png
256.png
310.png
384.png
512.png
  1. Convert 16 and 32 into favicon.ico:
convert \
  16.png \
  32.png \
  favicon.ico
  1. Configure your web server or reverse proxy to rewrite required paths.

See: https://realfavicongenerator.net/faq

server {
location /favicon.ico {
expires 7d;
add_header Cache-Control "public";
root /path/to/favicons;
}
location /apple-touch-icon.png {
expires 7d;
add_header Cache-Control "public";
alias /path/to/favicons/152.png;
}
location ~ ^/(?:android-chrome|apple-touch-icon|favicon|mstile)-\d+x(\d+).png$ {
expires 7d;
add_header Cache-Control "public";
alias /path/to/favicons/$1.png;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment