htaccess for Leverage浏览器缓存不起作用 [英] htaccess for Leverage browser caching not working

查看:123
本文介绍了htaccess for Leverage浏览器缓存不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到Leverage浏览器缓存问题。
我创建了这个.htaccess文件并在我的服务器上使用它,但它似乎没有工作,我从这里复制了这个 http://www.samaxes.com/2011/05/improving-web-performance-with-apache-and-htaccess/
我最喜欢犯一个基本的错误,所以任何帮助都会很好。
这里有一些细节。我正在研究一个子域,我们称之为sub和主域example。
所以我希望 http://sub.example.com/ 中有关htaccess文件的所有内容从事于。在我的服务器上
我将.htaccess文件放在sub的主目录中,例如单独的主目录。

I am having issues with Leverage browser caching. I have created this .htaccess file and am using it on my server but it doesnt appear to be working, i copied this from here "http://www.samaxes.com/2011/05/improving-web-performance-with-apache-and-htaccess/". I am most likly making a basic mistake so any help would be nice. here are some details. I am working on a subdomain lets call it "sub" and the main domain "example". so i want everything in http://sub.example.com/ for the htaccess file to work on. on my server i placed the .htaccess file in sub's main directory which is seperate to the main one for example.

我正在运行一个apache2服务器mod_headers和mod_expires也启用。

I am running an apache2 server with both mod_headers and mod_expires enabled also.

干杯。

<ifModule mod_deflate.c>
AddOutputFilterByType DEFLATE text/html text/xml text/css text/plain
AddOutputFilterByType DEFLATE image/svg+xml application/xhtml+xml application/xml
AddOutputFilterByType DEFLATE application/rdf+xml application/rss+xml application/atom+xml
AddOutputFilterByType DEFLATE text/javascript application/javascript application/x-javascript application/json
AddOutputFilterByType DEFLATE application/x-font-ttf application/x-font-otf
AddOutputFilterByType DEFLATE font/truetype font/opentype
</ifModule>
<ifModule mod_expires.c>
 ExpiresActive On
 ExpiresDefault "access plus 5 seconds"
 ExpiresByType image/x-icon "access plus 2592000 seconds"
 ExpiresByType image/jpeg "access plus 2592000 seconds"
 ExpiresByType image/png "access plus 2592000 seconds"
 ExpiresByType image/gif "access plus 2592000 seconds"
 ExpiresByType application/x-shockwave-flash "access plus 2592000 seconds"
 ExpiresByType text/css "access plus 604800 seconds"
 ExpiresByType text/javascript "access plus 216000 seconds"
 ExpiresByType application/javascript "access plus 216000 seconds"
 ExpiresByType application/x-javascript "access plus 216000 seconds"
 ExpiresByType text/html "access plus 600 seconds"
 ExpiresByType application/xhtml+xml "access plus 600 seconds"
 </ifModule>
 <filesMatch "\\.(ico|pdf|flv|jpg|jpeg|png|gif|swf|mp3|mp4)$">
 Header set Cache-Control "max-age=2592000, private"
 Header set Expires "Sun, 17 July 2013 20:00:00 GMT"
 </filesMatch>
 <filesMatch "\\.(css|css.gz)$">
 Header set Cache-Control "max-age=604800, private" 
 </filesMatch>
 <filesMatch "\\.(js|js.gz)$">
 Header set Cache-Control "max-age=604800, private"
 </filesMatch>
 <filesMatch "\\.(xml|txt)$">
 Header set Cache-Control "max-age=216000, private, must-revalidate"
 </filesMatch>
 <filesMatch "\\.(html|htm)$">
 Header set Cache-Control "max-age=7200, private, must-revalidate"
 </filesMatch>
 FileETag None


推荐答案

看起来非常混乱。

您还有多余的规则,例如

You also have redundant rules like

ExpiresByType application / javascriptaccess plus 216000秒

<filesMatch "\\.(js|js.gz)$">
Header set Cache-Control "max-age=604800, private"
</filesMatch>

尝试使用 html5-boilerplate 或结帐所有
h5bp服务器配置

Try using the cleaner (and up to date) rules from the html5-boilerplate or checkout all the h5bp server configs

这篇关于htaccess for Leverage浏览器缓存不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆