我的浏览器会缓存数据 URL 中的网站图标吗
我想使用以下 Base64 图标,也许还有一些 Base64 图像。
<link href="data:image/x-icon;base64,AAABAAEAEBAAAAAAAABoBQAAFgAAACgAAAAQAAAAIAAAAAEACAAAAAAAAAEAAAAAAAAAAAAAAAEAAAAAAA..AMAK3WxwAOWT0AK4RgAKHOvQA4hWUAP4lqAD2MagBQm3kATKSBAECcdP//AAD8/wAA+H8AAPA/AADwPwAA4B8AAMAPAACABwAAAgMAAI8BAADfgAAA/8AAAP/AAAD/4QAA//MAAP//AAA=" rel="icon" type="image/x-icon" />
这些会被我的浏览器缓存吗?
I would like to use the following base64 favicon and maybe some base64 images.
<link href="data:image/x-icon;base64,AAABAAEAEBAAAAAAAABoBQAAFgAAACgAAAAQAAAAIAAAAAEACAAAAAAAAAEAAAAAAAAAAAAAAAEAAAAAAA..AMAK3WxwAOWT0AK4RgAKHOvQA4hWUAP4lqAD2MagBQm3kATKSBAECcdP//AAD8/wAA+H8AAPA/AADwPwAA4B8AAMAPAACABwAAAgMAAI8BAADfgAAA/8AAAP/AAAD/4QAA//MAAP//AAA=" rel="icon" type="image/x-icon" />
Will these get cached by my browser?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
不会。数据 URI 不会与其包含的文档(例如 CSS 或 HTML 文件)分开缓存,因此每次重新下载包含的文档时都会下载数据。
来源
No. Data URIs are not separately cached from their containing documents (e.g. CSS or HTML files) so data is downloaded every time the containing documents are redownloaded.
Source
缓存网站的 favicon 实际上是推荐作为加快网站速度的性能最佳实践。
例如,Google 不会浪费额外的宝贵字节在其主页的源代码中包含网站图标(使用
或数据 URI)。
相反,他们使用设置为遥远未来的 HTTP 标头来提供他们的收藏图标。
Cache-Control:私有,max-age=31536000
(31,536,000 秒 = 365 天)。如果您有兴趣控制网站图标的“新鲜度”,则可以使用缓存控制和 HTTP 标头 - 例如,如果您计划更改图标或不希望对其进行缓存,则可以对其进行调整因此。
的示例:
使用 Apache 和 mod_expires 模块控制服务器响应中 Expires HTTP 标头的设置和 Cache-Control HTTP 标头的 max-age 指令。到期日期可以设置为相对于源文件上次修改的时间或客户端访问的时间。
Caching your site's favicon is actually recommended as a Performance Best Practice for Speeding Up Your Web Site.
Google, for example, doesn't waste the extra precious bytes to include a favicon in the source code of its homepage (either using a
<link />
or a Data URI).Instead, they serve their favicon with a HTTP header set far into the future.
Cache-Control: private, max-age=31536000
(31,536,000 seconds = 365 days).If you're interested in controlling the "freshness" of your site's favicon, you can use Cache-Control and HTTP Headers — for example if you are planning on changing the favicon or don't want it to be cached, you can adjust it accordingly.
An example using Apache and mod_expires:
This module controls the setting of the Expires HTTP header and the max-age directive of the Cache-Control HTTP header in server responses. The expiration date can set to be relative to either the time the source file was last modified, or to the time of the client access.