我的过期时间、缓存控制和编译指示 HTTP 请求标头字段应设置为什么?

发布于 2024-09-25 00:16:53 字数 383 浏览 2 评论 0原文

我有一个网站,大约每月更新一次内容。当我检查 HTTP 请求标头字段时,我得到以下输出:

Expires: Thu, 19 Nov 1981 08:52:00 GMT  
Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0   
Pragma: no-cache

我的问题是,考虑到更新内容的频率,我正在考虑手动设置这些字段以允许缓存站点。我正在使用 php header();命令这样做。

因此,我的问题是:我的 expires、cache-control 和 pragma HTTP 请求标头字段应该设置为什么?另外,除了这些字段之外,我还应该设置其他字段吗?

I have a website in which I update the content approximately once monthly. When I check the HTTP request header fields, I get the following output:

Expires: Thu, 19 Nov 1981 08:52:00 GMT  
Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0   
Pragma: no-cache

My question is, given the frequency at which I update content, I am thinking about manually setting these fields to allow cache of the site. I am using the php header(); command to do so.

Therefore, my question is: what should my expires, cache-control, and pragma HTTP request header fields be set to? Also, should I be setting any other fields in addition to those?

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

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

发布评论

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

评论(2

似梦非梦 2024-10-02 00:16:53

您可以考虑使用 ETAG - http://en.wikipedia.org/wiki/HTTP_ETag

You could look into using ETAGs - http://en.wikipedia.org/wiki/HTTP_ETag

哭了丶谁疼 2024-10-02 00:16:53

您的 Expires 标头应该是未来的日期,届时内容将过期,并且缓存将被迫再次获取它。

摆脱 Pragma 标头

对于 Cache-Control 您可以添加:
public max-age=2592000

假设您希望它缓存 30 秒。

为了更好地控制,您应该遵循 hafichuk 的建议并使用 ETag。

有关缓存标头的参考,请查看 标头

Your Expires header should be the date in the future at which time the content will expire and caches will be forced to fetch it again.

Get rid of the Pragma header

For Cache-Control you can add:
public max-age=2592000

Assuming you want it cached for 30 seconds.

For greater control you should follow hafichuk's advice and use ETags.

For references on cache headers check out Headers

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