Isn't it silly that a tiny favicon requires yet another HTTP request? How can I put the favicon into a sprite?

后端 未结 14 1834
暖寄归人
暖寄归人 2020-11-29 14:58

Everybody knows how to set up a favicon.ico link in HTML:



        
14条回答
  •  没有蜡笔的小新
    2020-11-29 15:22

    Not really an answer to the question but simply to compliment the answers given by Marcel and yahelc I offer an elegant solution to the 404 favicon issue.

    Because some apps and browsers and whatnot check for a favicon.com and if the icon is not found in the site root you can simply respond to the request with the 204 response header.

    Apache Examples:

    Apache option one (and my favorite), simple one liner in your .htacces or .conf:

    Redirect 204 /favicon.ico
    

    Apache option two:

    
        ErrorDocument 204 ""
    
    

    For further reading, there is nice blog post by Stoyan Stefanov at http://www.phpied.com/204-no-content/

提交回复
热议问题