-24
Did you know that Google provides a free API to retrieve the favicon for any website?
(programming.dev)
Welcome to the main community in programming.dev! Feel free to post anything relating to programming here!
Cross posting is strongly encouraged in the instance. If you feel your post or another person's post makes sense in another community cross post into it.
Hope you enjoy the instance!
Rules
Follow the wormhole through a path of communities !webdev@programming.dev
I’m not sure what you’re talking about. You need to know the name of the file before you can download it.
For instance, my lemmy client, says in its HTML that its favicon is
<link id="favicon" rel="shortcut icon" type="image/x-icon" href="https://sopuli.xyz/pictrs/image/9c6eeb58-bf66-4a15-9537-0a822f3c4feb.png">
. If I were to blindly download/favicon.ico
, I’d naturally get a 404 page:Indeed. And /favicon.ico might not be a Windows ICO file, but instead be a PNG, GIF, or some other image format. I thought that's what you were (correctly) pointing out when you wrote "it doesn’t have to be an *.ico file". In such cases, the HTTP Content-Type field tells what image format it is.
Ah, so it turns out you were thinking of cases where /favicon.ico doesn't exist at all. That can also happen, but your suggestion to "try different file extensions" is not the answer, as you can see if you try to curl /favicon.png, /favicon.gif, etc. The correct approach is to parse a web page's HTML in search of a favicon URL, which you did in your above reply, but that's not the same thing as what you originally suggested.