浏览器访问网络图片的favicon是哪来的?

阅读 2.5k
2 个回答

浏览器在服务器根目录下查找favicon.ico,找到就会添加在网页title左侧,没找到的话就404

favicon 一般可以通过 <head> 里的 <link rel="icon"> 来指定。

没有的话

In the absence of a link with the icon keyword, for Document objects obtained over HTTP or HTTPS, user agents may instead run these steps in parallel:

  1. Let request be a new request whose URL is the absolute URL obtained by resolving the URL "/favicon.ico" against the document’s URL, client is the Document object’s Window object’s environment settings object, type is "image", destination is "subresource", synchronous flag is set, credentials mode is "include", and whose use-URL-credentials flag is set.
  2. Let response be the result of fetching request.
  3. Use response’s unsafe response as an icon as if it had been declared using the icon keyword.

也就是会去拼一个 /favicon.ico 的 url 出来请求 favicon 。

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题
宣传栏