了解网络浏览器中的图像缓存

发布于 2024-10-03 05:59:56 字数 94 浏览 0 评论 0原文

影响网络浏览器中图像缓存的完整因素有哪些? 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

2024-10-10 05:59:56

完整的因素集:

  • 影响缓存
  • 用户代理(浏览器)内置缓存行为的 HTTP 标头
    • 可以通过用户设置进行修改,具体取决于 UA
    • 包括可能会在每个会话中使用然后清除单独缓存的隐私浏览模式
  • 用户操作的单独缓存,例如手动清除缓存

Web 开发人员几乎没有控制权,但这很好。请记住,缓存是为了最终用户的利益而进行的,通常是为了减少页面加载时间,并且您通常不可能了解每个用户特定的所有注意事项。

可以控制的是过期时间和无缓存行为。这些分别指定用户想要重新获取资源,因为预计资源已更改或由于其他原因不应缓存。

浏览器对待图像的方式可能与其他资源不同(主要是未指定时的默认过期时间不同),但您可以发送任何资源的 HTTP 标头。

The complete set of factors:

  • HTTP headers which affect caching
  • the user agent's (browser's) built-in caching behavior
    • may be modified through user settings, depending on UA
    • including private browsing modes that may use and then clear a separate cache per session
  • the user's actions, such as manually clearing the cache

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.

乖乖兔^ω^ 2024-10-10 05:59:56

从客户端检查客户端浏览器是否向服务器发送 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文