如何在客户端缓存文件,以便浏览器甚至不再费心再次请求它?

发布于 2024-09-05 04:37:46 字数 293 浏览 2 评论 0原文

我发回带有以下 HTTP 响应标头的图像:

Cache-Control: private,max-age=86400

我的理解是,浏览器在 24 小时内不应该请求该文件(86,400 = 60s * 60m * 24h)。

我在后续请求中看到的是,它仍然要求提供该文件,但返回“304 Not Modified”。这很好,但我什至想删除该请求/响应。

需要什么标头才能防止浏览器甚至懒得去请求该文件,而只是让它盲目地使用本地缓存中的文件,直到该文件过期?

I send back an image with the following HTTP response header:

Cache-Control: private,max-age=86400

My understanding is that the browser should not even ask for this file for 24 hours (86,400 = 60s * 60m * 24h).

What I'm seeing on subsequent requests is that it still asks for the file, but gets back a "304 Not Modified." This is good, but I want to remove even that request/response.

What header is required to prevent the browser from even bothering to ask for the file, and just have it blindly use the file it has in local cache, until that file expires?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

酒废 2024-09-12 04:37:46

这完全取决于您如何测试。在 Firefox 3.6 和 IE8 上,单击一个链接,然后单击一个将您移回首页的链接,将正确使用 max-age 的缓存。在 URL 字段中再次点击 Return 键将显示相同的行为。

但是,按 F5 将再次询问该文件,但允许 304 响应。

按 Ctrl+F5 将始终再次请求该文件,并将 Cache-Control 和 Pragma 设置为 no-cache,强制返回 200 响应。

It all really depends on how you're testing this. On Firefox 3.6 and IE8, clicking on a link and then on a link that move you back to the first page will use the cache correctly with max-age. Hitting the Return key again in the URL field will show the same behavior.

However, hitting F5 will ask again for the file but allows 304 responses.

Hitting Ctrl+F5 will always ask again for the file, with Cache-Control and Pragma set to no-cache, forcing a 200 response.

地狱即天堂 2024-09-12 04:37:46

这根本无法在 HTML < 中可靠地完成。 5.

您可以在 HTML5 或使用浏览器扩展程序(例如 Gears)来提供此功能。

This simply can't be done reliably in HTML < 5.

You could use client side storage in HTML5 or use a browser extension such as Gears to provide this functionality.

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