了解网络浏览器中的图像缓存
影响网络浏览器中图像缓存的完整因素有哪些? Web 开发人员对此有多少控制权,浏览器设置有多少?对于其他类型的资产(即脚本、音频)是否有不同的考虑因素?
谢谢
What are the complete set of factors that affect image caching in web browsers? How much control does a web developer have over this, and how much is browser settings? Are there different considerations for other types of assets (i.e. scripts, audio)?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
完整的因素集:
Web 开发人员几乎没有控制权,但这很好。请记住,缓存是为了最终用户的利益而进行的,通常是为了减少页面加载时间,并且您通常不可能了解每个用户特定的所有注意事项。
您可以控制的是过期时间和无缓存行为。这些分别指定用户想要重新获取资源,因为预计资源已更改或由于其他原因不应缓存。
浏览器对待图像的方式可能与其他资源不同(主要是未指定时的默认过期时间不同),但您可以发送任何资源的 HTTP 标头。
The complete set of factors:
Web developers have very little control, but this is fine. Remember that caching is done for the benefit of the end user, usually to reduce page load time, and it's generally infeasible for you to know all the considerations specific to every user.
The bit you can control is expiration time and no-cache behavior. These respectively specify that the user wants to refetch the resource because it is expected to have changed or should not be cached for other reasons.
Browsers may treat images differently than other resources (mainly differing in default expiration time when unspecified), but you can send HTTP headers for any resource.
从客户端检查客户端浏览器是否向服务器发送 If-Modified-Since 标头。如果客户端发送标头,IIS 将响应 304 Not Modified,因此客户端将使用其本地缓存来显示/使用该文件。
客户端设置对此负责。 IE->工具->互联网选项 ->浏览历史记录->设置->自动将确保这发生。不同的浏览器对此设置有不同的区域。
对于脚本/音频,您可以将它们放在一个特殊的内容文件夹中,并且只需从服务器设置内容过期时间,以便服务器在需要时向客户端发送适当的信息以缓存文件。但这不会是开发人员设置。
开发人员设置通常适用于动态文件。根据语言[在 ASP.NET 中,OutputCache 指令创建不同的缓存标头],这会有所不同。
From the client side, check if the client browser sends If-Modified-Since header to the server. If the client sends the header, IIS will respond 304 Not Modified and hence, the client will use its local cache to display/use the file.
The client settings are responsible for this. IE -> Tools -> Internet Options -> Browsing History -> Settings -> Automatically will ensure that this takes place. Different browsers will have different regions for this setting.
For scripts/audio you can place them in a special folder for content, and simply set content expiration from your server so that the server sends appropriate information to the client to cache the file when it is asked for. This won't be a developer setting though.
The developer setting is typically for the Dynamic files. Based on language [in ASP.NET, OutputCache directive creates different cache headers] this would vary.