For people still not getting the favicon with above codes;
-
Most browsers support getting the favicon by sending a request (
/favicon.ico) themselves, instead of in the html. -
Another solution is provided by Google.
To get the favicon for a domain, use:
https://s2.googleusercontent.com/s2/favicons?domain=www.stackoverflow.comTo get the favicon for an URL, use:
https://s2.googleusercontent.com/s2/favicons?domain_url=https://www.stackoverflow.com