gpt4 book ai didi

apache - Last-Modified 不适用于 .htaccess

转载 作者:行者123 更新时间:2023-12-04 05:56:44 25 4
gpt4 key购买 nike

我很想实现浏览器缓存并遵循 Google PageSpeed 的建议,将 Last-Modified 设置为“过去足够远”的数据。我的 .htaccess 中有以下内容:

<IfModule mod_headers.c>
<FilesMatch "\.(json|pdf|swf|bmp|gif|jpeg|jpg|png|svg|tiff|ico|flv|js)$">
Header Set Last-Modified "Fri, 01 Jan 2010 12:00:00 GMT"
</FilesMatch>
</IfModule>

我的服务器上安装了 mod_headers。

不幸的是,Google PageSpeed 仍然提示并警告我:

Leverage browser caching

The following cacheable resources have a short freshness lifetime. Specify an expiration at least one week in the future for the following resources:

然后列出 PNG、GIF、JPG 等。Yahoo YSlow 说的基本相同。

查看我应该缓存的资源之一的响应 header ,我看到了:

Date:           Tue, 19 Oct 2010 20:12:04 GMT
Server: Apache/2.2.14 (Ubuntu)
Last-Modified: Tue, 07 Sep 2010 23:51:33 GMT
Etag: "2e0e34-2a43-48fb413a96a20"
Accept-Ranges: bytes
Content-Length: 10819
Content-Type: image/png

如您所见,Last-Modified 数据与我在 .htaccess 中指定的不匹配。

任何想法我做错了什么?

最佳答案

删除 Last-Modified 不是 Google PageSpeed 要求的。当浏览器请求静态文件时,它希望在您的服务器响应中看到以下 header :

Cache-Control max-age=...
Expires ...

服务器将放置值来代替点。

为此,您只需在 .htaccess 中添加以下行:

<IfModule mod_headers.c>
<FilesMatch "\.(json|pdf|swf|bmp|gif|jpeg|jpg|png|svg|tiff|ico|flv|js)$">
ExpiresActive On
ExpiresDefault "access plus 1 year"
Header append Cache-Control "public"
</FilesMatch>
</IfModule>

您会看到 Google PageSpeed 停止提示。

关于apache - Last-Modified 不适用于 .htaccess,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3982654/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com