我的PHP生成的缩略图文件和组合的JavaScript和CSS文件(都有其到期date和caching=公共设置等)有时会返回完整的内容,有时他们从代理caching加载!
这是redbot.org给出的评论,有时候:
* HTTP允许客户端发出有条件的请求来查看他们拥有的副本是否仍然有效。 由于此响应具有Last-Modified标头,因此客户端应该能够使用If-Modified-Since请求标头进行validation。 RED已经这样做了,发现资源发送完整的响应,即使它没有改变 ,表明它不支持最后修改validation。**
PHP缩略图生成器头
header ("Content-type: image/jpeg"); header ("Last-Modified: " . gmdate("D, d MYH:i:s", time() - 404800000)." GMT"); header ("Expires: " . gmdate("D, d MYH:i:s", time() + 2419200) . " GMT"); header ("Cache-Control: public, max-age=2419200");
htaccess的
<IfModule mod_headers.c> ExpiresActive On ExpiresDefault M172800 ##### DEFAULT EXPIRES <FilesMatch "\\.(ico|jpg|png|gif|svg|swf|css|js|fon|xml|pdf|flv)$"> ExpiresDefault M1209600 Header set Cache-Control "max-age=1209600, public" </FilesMatch> ##### DYNAMIC PAGES <FilesMatch "\\.(php|cgi|pl)$"> ExpiresDefault M7200 Header set Cache-Control "public, max-age=7200" </FilesMatch> Header unset Pragma Header unset ETag Header unset Last-Modified FileETag None </IfModule>
谷歌SpeedTest提供了91/100得分的顶部它说:并列出所有的文件, 除了PHP生成的文件 ,具有明确的过期头设置((仍然返回完整的内容!??)它说:
以下资源缺lesscachingvalidation程序。 不指定cachingvalidation程序的资源不能被有效地刷新。 指定Last-Modified或ETag标头以启用下列资源的高速cachingvalidation。
你可以使用Firebug并粘贴HTTP响应头文件。 我有一种感觉,即使在您的代码中,您将caching控制设置为Public,Apache将重写,因为对于Php文件types,您将Cache-Control设置为私有。
有一件事你可以从Apacheconfiguration中删除dynamic页面的caching设置。 这应该可以解决问题,因为代理不会在没有正确标题的情况下caching响应。
编辑
嗨,山姆,重温你的问题,我find了解决问题的办法。 下面的代码片段似乎是一个问题。 在你的Php的输出中,Last-Modified头部总是会改变,当浏览器发送一个304如果被修改的请求,它看到一个改变,因此重新请求这个内容。
header ("Last-Modified: " . gmdate("D, d MYH:i:s", time() - 404800000)." GMT");
从您的内容中取消设置最后修改和ETag以加速网站。 这个网站也提供了一些优秀的技巧。
http://www.askapache.com/htaccess/apache-speed-last-modified.html
我在htaccess文件中添加了下面的代码,当http://pagespeed.googlelabs.com/在铬我得到杠杆浏览器caching,现在已经解决,但现在它给错误指定cachingvalidation,如何做到这一点,我已经添加caching控件,下面是代码
<"ifModule mod_gzip.c> mod_gzip_on Yes mod_gzip_dechunk Yes mod_gzip_item_include file \\.(html?|txt|css|js|php|pl)$ mod_gzip_item_include handler ^cgi-script$ mod_gzip_item_include mime ^text/.* mod_gzip_item_include mime ^application/x-javascript.* mod_gzip_item_exclude mime ^image/.* mod_gzip_item_exclude rspheader ^Content-Encoding:.*gzip.* <"/ifModule> <"ifModule mod_expires.c> ExpiresActive On ExpiresDefault "access plus 1 seconds" ExpiresByType text/html "access plus 1 seconds" ExpiresByType image/gif "access plus 2592000 seconds" ExpiresByType image/jpeg "access plus 2592000 seconds" ExpiresByType image/png "access plus 2592000 seconds" ExpiresByType text/css "access plus 604800 seconds" ExpiresByType application/x-javascript "access plus 216000 seconds" <"/ifModule> <"ifModule mod_headers.c> <"filesMatch "\\\\.(ico|pdf|flv|jpg|jpeg|png|gif|swf)$"> Header set Cache-Control "max-age=2592000, public" <"/filesMatch> <"filesMatch "\\\\.(css)$"> Header set Cache-Control "max-age=604800, public" <"/filesMatch> <"filesMatch "\\\\.(js)$"> Header set Cache-Control "max-age=216000, private" <"/filesMatch> <"filesMatch "\\\\.(xml|txt)$"> Header set Cache-Control "max-age=216000, public, must-revalidate" <"/filesMatch> <"filesMatch "\\\\.(html|htm|php)$"> Header set Cache-Control "max-age=1, private, must-revalidate" <"/filesMatch> <"/ifModule> <"ifModule mod_headers.c> Header unset ETag <"/ifModule> FileETag None <"ifModule mod_headers.c> Header unset Last-Modified <"/ifModule>