的.htaccess:如何与QUOT;指定缓存验证及QUOT;?

编程入门 行业动态 更新时间:2024-10-22 23:12:48
本文介绍了的.htaccess:如何与QUOT;指定缓存验证及QUOT;?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我在我的网站上运行谷歌PageSpeed​​和它的告诉我,我需要 指定缓存验证。

I'm running Google PageSpeed on my site and it's tell me that I need to "Specify a cache validator."

以下资源缺少缓存验证。不指定缓存验证资源不能有效地刷新。指定一个Last-Modified或ETag头启用缓存验证以下资源:

The following resources are missing a cache validator. Resources that do not specify a cache validator cannot be refreshed efficiently. Specify a Last-Modified or ETag header to enable cache validation for the following resources:

...然后列出图片,CSS,JS等。

... then it lists images, CSS, JS, etc.

据$c$c.google/speed/page-speed/docs/caching.html#LeverageBrowserCaching:

设置Last-Modified日期,以最后一次资源被改变。如果Last-Modified日期足够远不够,在过去,很可能是浏览器不会重新读取它。

Set the Last-Modified date to the last time the resource was changed. If the Last-Modified date is sufficiently far enough in the past, chances are the browser won't refetch it.

我在我的.htaccess如下:

I have the following in my .htaccess:

<IfModule mod_headers.c> <FilesMatch "\.(bmp|css|flv|gif|ico|jpg|jpeg|js|pdf|png|svg|swf|tif|tiff)$"> Header set Last-Modified "Tue, 31 Aug 2010 00:00:00 GMT" </FilesMatch> </IfModule>

我是什么做错了吗?

What am I doing wrong?

推荐答案

我想你遇到的问题是过期:而不是上次修改:。阿帕奇将在默认情况下发送的文件的Last-Modified:基于文件的日期头。我建议拆除上部code和具有以下替换它:

I think the problem you are having is with Expire: and not with Last-Modified:. Apache would by default send the file Last-Modified: header based on the file date. I suggest removing the upper code and replacing it with the following:

<IfModule mod_expires.c> ExpiresActive On ExpiresDefault "access plus 1 year" </IfModule>

尝试使用,如果它没有工作,尝试添加这个问题,以及:

Try with that, if it didn't work try adding this as well:

<IfModule mod_headers.c> <FilesMatch "\.(bmp|css|flv|gif|ico|jpg|jpeg|js|pdf|png|svg|swf|tif|tiff)$"> Header set Last-Modified "Mon, 31 Aug 2009 00:00:00 GMT" </FilesMatch> </IfModule>

更多推荐

的.htaccess:如何与QUOT;指定缓存验证及QUOT;?

本文发布于:2023-11-01 02:20:21,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1547969.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:缓存   htaccess   QUOT

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!