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

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

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



        
14条回答
  •  心在旅途
    2020-11-29 15:01

    I found an interesting solution on this page. It is german but you will be able to understand the code.

    You put the base64 data of the icon into an external stylesheet, so it will be cached. In the head of your website you have to define the favicon with an id and the favicon is set as a background-image in the stylesheet for that id.

    link#icon {
        background-image:url("data:image/x-icon;base64,");
    }
    

    and the html

    
        
            
            
            ...
        
        
            ...
        
    
    

提交回复
热议问题