可以做“相对”的事情 HTTP 标头过期?

发布于 2024-07-29 20:51:44 字数 56 浏览 3 评论 0原文

例如,我希望我的静态文件在首次下载后 7 天过期。 我应该将 Expires 标头值设置为多少?

For example, I want my static files to expire 7 days after they're first downloaded. What should I set the Expires header value to be?

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

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

发布评论

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

评论(2

机场等船 2024-08-05 20:51:44

只是偶然发现了这个试图找到其他东西 - 但在这种情况下你不应该使用 Expires。 使用 Cache-Control:

Cache-Control: public, max-age=604800

(604800 是 7 天(以秒为单位))。

Just stumbled across this trying to find something else — but you shouldn’t be using Expires in this case. Use Cache-Control:

Cache-Control: public, max-age=604800

(604800 is 7 days in seconds).

只为一人 2024-08-05 20:51:44

您需要在服务器端执行此操作。 生成计算该值的时间戳,然后发送回包含该值的标头。

PHP 示例

header('Expires: ' . gmdate('D, d M Y H:i:s', strtotime("+7 days")));

You need to do this server side. Generate the timestamp calculating the value, then send back the header with that value.

Example with PHP

header('Expires: ' . gmdate('D, d M Y H:i:s', strtotime("+7 days")));
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文