Did you know?
Google offers a secret URL that can automatically pull the favicon image of any domain. Cherries on the cake, we can ask for different sizes and the images returned are in PNG format (not ICO), meaning they will render correctly in all browsers using the <img>
tag.
The API works using a simple GET:
https://www.google.com/s2/favicons?domain=${domain}&sz=${size}
The query parameters are:
domain
: mandatory, the domain you are interested in,sz
: optional, a size hint such as256
.
In case the right size is not found, it will return the default one, usually 16x16.
cdn.hashnode.com/res/hashnode/image/upload/..
cdn.hashnode.com/res/hashnode/image/upload/.. (nothing found for 512x512, so returns a 16x16 PNG)
cdn.hashnode.com/res/hashnode/image/upload/.. (yep, sometimes the quality is far from optimal)
UPDATE: similar services
Privacy-friendly search engine DuckDuckGo also has one similar to Google one: icons.duckduckgo.com/ip3/dev.to.ico.
Another service called Icon Horse has some additional features: icon.horse/icon/dev.to.
Finally, there is also favicongrabber.com. The call looks like:
http://favicongrabber.com/api/grab/dev.to
The response is a JSON with all the available icons (use ?pretty=true
for nice json formatting):
{
"domain": "dev.to",
"icons": [
{
"sizes": "192x192",
"src": "https://res.cloudinary.com/practicaldev/image/fetch/s--t7tVouP9--/c_limit,f_png,fl_progressive,q_80,w_192/https:/practicaldev-herokuapp-com.freetls.fastly.net/assets/devlogo-pwa-512.png"
},
...
}
However, I got some gateway timeouts... Trying favicongrabber.com/api/grab/stacko... currently returns:
{"error":"General API error."}