开发者

How to prevent the browser from asking for the favicon?

开发者 https://www.devze.com 2023-02-08 11:57 出处:网络
Is there some directive I could use in my HTML to tell开发者_如何学编程 the browser not to ask for the favicon?Add this line.

Is there some directive I could use in my HTML to tell开发者_如何学编程 the browser not to ask for the favicon?


Add this line.

<link rel="icon" href="data:,">

This assigns an empty data URL to the favicon’s element which specifies the location of the external resource. This trick stops the user’s browser from sending an automatic HTTP request for the favicon.

This has some more details


No, I don't think there is. From Wikipedia:

Most web browsers do not require any HTML to retrieve a favicon that conforms to the de facto file name and type (favicon.ico) located in the web site's root. If no favicon link is detected upon HTML page load completion and no previous site visits are recorded in the browser's history, a favicon.ico is requested automatically.[8]

The only thing you could do is explicitly point the browser to a different location (that for example could return a 204 no content)

<link rel="shortcut icon" href="http://www.example.com/my_empty_resource" />


You could try pointing the <link> at a data URL. As commented below, IE will not like this, though.

Example (from 11011.net):

<link rel="icon" type="image/gif" href="data:image/gif;base64,R0lGODlhEAAQAIAAAAAAAAAAACH5BAkAAAEALAAAAAAQABAAAAIgjI+py+0PEQiT1lkNpppnz4HfdoEH2W1nCJRfBMfyfBQAOw==" />

Edited to reflect Pekka's concern regarding IE.


If you are not using HTML and its auto generated by Flask or some frameworks you can always add a dummy route in the app to just return dummy text to fix this issue.

Eg for Python Flask Application.

@app.route('/favicon.ico')
def favicon():
    return 'dummy', 200
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号