Html 将您的 favicon.ico 文件放在非根路径中是个坏主意吗?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/21359342/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Is putting your favicon.ico file in a non-root path a bad idea?
提问by Kaizer Sozay
When and how do browsers request the favicon.ico file? Do they always check for it in root, or do they read the content of the webpage first to see if the page specifies the location?
浏览器何时以及如何请求 favicon.ico 文件?他们总是在 root 中检查它,还是先阅读网页的内容以查看页面是否指定了位置?
I have my favicon.ico path in /images There is the following tag in each of my pages:
我的 favicon.ico 路径在 /images 我的每个页面中都有以下标签:
<link rel="shortcut icon" href="images/favicon.ico">
When I load the page in my browser, it seems to work (I can see the file), but I don't know whether they are making bad requests to my root folder first (where the file doesn't exist), and are later making a request to the link.
当我在浏览器中加载页面时,它似乎可以工作(我可以看到文件),但我不知道他们是否首先向我的根文件夹(文件不存在的地方)发出了错误的请求,并且稍后向链接发出请求。
I want to minimze 404's and wasted bandwidth, by the browser making incorrect calls to my site.
我想通过浏览器对我的网站进行错误调用来最小化 404 和浪费的带宽。
EDIT: I'm looking for some insight into how browsers work, and request this file, so my site structure is efficient.
编辑:我正在寻找有关浏览器如何工作的一些见解,并请求此文件,因此我的站点结构是有效的。
回答by duskwuff -inactive-
Remember that not all requests to your site are for HTML pages! Requests for non-HTML content, like bare image files (e.g, viewing http://example.com/image.jpegdirectly in the browser), cannot see a <link>
tag. Therefore, they must fall back to searching for the shortcut icon in the standard location at /favicon.ico
.
请记住,并非所有对您网站的请求都是针对 HTML 页面的!对非 HTML 内容的请求,如裸图像文件(例如,直接在浏览器中查看http://example.com/image.jpeg),无法看到<link>
标签。因此,他们必须退回到在标准位置搜索快捷方式图标/favicon.ico
。
This still doesn't mean that this needs to be the canonical location, though! You can still keep it in /images/favicon.ico
if you want - just make sure that a redirect is in place from /favicon.ico
to wherever your preferred location is.
但这仍然并不意味着这需要是规范位置!/images/favicon.ico
如果需要,您仍然可以保留它- 只需确保从/favicon.ico
您的首选位置重定向到任何位置即可。