Html 为什么我在不使用它时看到 404 (Not Found) 错误无法加载 favicon.ico?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/39149846/
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
Why am I seeing a 404 (Not Found) error failed to load favicon.ico when not using this?
提问by John Smith
Synopsis
概要
After creating a simple HTML template for testing purpose, with no favicon.ico, I receive an error in the console "Failed to load resource: the server responded with a status of 404 (Not Found)" | "http://127.0.0.1:47021/favicon.ico".
创建用于测试目的的简单 HTML 模板后,没有 favicon.ico,我在控制台中收到错误“无法加载资源:服务器响应状态为 404(未找到)” | “ http://127.0.0.1:47021/favicon.ico”。
I am trying to figure out where this error is coming from and wondered if someone had any ideas to point me in the right direction.
我试图找出这个错误的来源,并想知道是否有人有任何想法可以将我指向正确的方向。
My HTML page looks like this:
我的 HTML 页面如下所示:
<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<title>Simple JavaScript Tester 01</title>
</head>
<body>
<script src="script.js"></script>
</body>
</html>
When I run this page in Chrome browser and open the console, I see the error message "Failed to load resource: the server responded with a status of 404 (Not Found)" | "http://127.0.0.1:47021/favicon.ico". I am running this on a local IIS server. I see this same error message each time I create a new page.
当我在 Chrome 浏览器中运行此页面并打开控制台时,我看到错误消息“无法加载资源:服务器响应状态为 404(未找到)” | “ http://127.0.0.1:47021/favicon.ico”。我在本地 IIS 服务器上运行它。每次创建新页面时,我都会看到相同的错误消息。
Is it possible this error is coming from another page on my IIS server that I am unaware of?
此错误是否可能来自我不知道的 IIS 服务器上的另一个页面?
采纳答案by makadus
Google favicon generator and make an icon. Name it favicon.ico and drop it in your webroot.
谷歌图标生成器并制作一个图标。将其命名为 favicon.ico 并将其放在您的 webroot 中。
See if this helps.
看看这是否有帮助。
Also here is a tutorial on favicon: https://www.w3.org/2005/10/howto-favicon
这里还有一个关于 favicon 的教程:https: //www.w3.org/2005/10/howto-favicon
回答by pollux1er
By adding this to the header section, you will definitely remove the error in the console log:
通过将此添加到标题部分,您肯定会删除控制台日志中的错误:
<link rel="shortcut icon" href="">
回答by Hyman Marchetti
Because your browser always looks for the favicon.ico even if you don't specify it within your HTML.
因为您的浏览器总是会查找 favicon.ico,即使您没有在 HTML 中指定它。
So I'd suggest just creating one and placing it in the root of your website.
所以我建议只创建一个并将其放置在您网站的根目录中。
回答by David Fawzy
<link rel="shortcut icon" href="~/favicon.ico">
You can't actually stop browsers requesting the image. However if you do have a favicon it can be cached by the browser which can reduce the number of requests coming in. so if you have the favicon in the root folder of the application the link above should work
您实际上无法阻止浏览器请求图像。但是,如果您确实有收藏夹图标,它可以被浏览器缓存,这可以减少进入的请求数量。因此,如果您在应用程序的根文件夹中有收藏夹图标,则上面的链接应该可以使用