优化.htaccesscaching?

我试图让Google PageSpeed快乐,但我的.htaccess技能是有限的。 我特别努力浏览器和代理caching有没有人有我可以使用的模板?

这是我到目前为止的压缩:

# JavaScript MIME type issues: # 1. Apache uses "application/javascript": http://svn.apache.org/repos/asf/httpd/httpd/branches/1.3.x/conf/mime.types # 2. IIS uses "application/x-javascript": http://technet.microsoft.com/en-us/library/bb742440.aspx # 3. SVG specification says it is text/ecmascript: http://www.w3.org/TR/2001/REC-SVG-20010904/script.html#ScriptElement # 4. HTML specification says it is text/javascript: http://www.w3.org/TR/1999/REC-html401-19991224/interact/scripts.html#h-18.2.2.2 # 5. "text/ecmascript" and "text/javascript" are considered obsolete: http://www.rfc-editor.org/rfc/rfc4329.txt #================================================================================================== # Compression: http://code.google.com/speed/page-speed/docs/payload.html#GzipCompression #================================================================================================== <IfModule mod_deflate.c> AddOutputFilterByType DEFLATE application/atom+xml AddOutputFilterByType DEFLATE application/json AddOutputFilterByType DEFLATE application/xhtml+xml AddOutputFilterByType DEFLATE application/xml AddOutputFilterByType DEFLATE text/css AddOutputFilterByType DEFLATE text/html AddOutputFilterByType DEFLATE text/plain AddOutputFilterByType DEFLATE text/xml # The following MIME types are in the process of registration AddOutputFilterByType DEFLATE application/xslt+xml AddOutputFilterByType DEFLATE image/svg+xml # The following MIME types are NOT registered AddOutputFilterByType DEFLATE application/mathml+xml AddOutputFilterByType DEFLATE application/rss+xml # Compress JavaScript; make sure to list all possible MIME types for JavaScript AddOutputFilterByType DEFLATE application/javascript AddOutputFilterByType DEFLATE application/x-javascript AddOutputFilterByType DEFLATE text/ecmascript AddOutputFilterByType DEFLATE text/javascript </IfModule> #-------------------------------------------------------------------------------------------------- 

这是您可以使用的模板。 我从某人那里得到它,不知道谁是原作者,但可以很好地输出yslow插件( http://developer.yahoo.com/yslow/ )。

 <IfModule mod_rewrite.c> RewriteEngine On RewriteBase / </IfModule> # if you don't use filenames to version, lower the css and js to something like # "access plus 1 week" or so <IfModule mod_expires.c> Header set cache-control: public ExpiresActive on # Perhaps better to whitelist expires rules? Perhaps. ExpiresDefault "access plus 1 month" # cache.manifest needs re-reqeusts in FF 3.6 (thx Remy ~Introducing HTML5) ExpiresByType text/cache-manifest "access plus 0 seconds" # your document html ExpiresByType text/html "access" # rss feed ExpiresByType application/rss+xml "access plus 1 hour" # favicon (cannot be renamed) ExpiresByType image/vnd.microsoft.icon "access plus 1 week" # favicon (cannot be renamed) ExpiresByType image/vnd.microsoft.icon "access plus 1 week" # media: images, video, audio ExpiresByType image/png "access plus 1 month" ExpiresByType image/jpg "access plus 1 month" ExpiresByType image/jpeg "access plus 1 month" ExpiresByType video/ogg "access plus 1 month" ExpiresByType audio/ogg "access plus 1 month" ExpiresByType video/mp4 "access plus 1 month" # webfonts ExpiresByType font/ttf "access plus 1 month" ExpiresByType font/woff "access plus 1 month" ExpiresByType image/svg+xml "access plus 1 month" # css and javascript ExpiresByType text/css "access plus 1 month" ExpiresByType application/javascript "access plus 1 month" ExpiresByType text/javascript "access plus 1 month" </IfModule> # Since we're sending far-future expires, we don't need ETags for # static content. # developer.yahoo.com/performance/rules.html#etags FileETag None # use utf-8 encoding for anything served text/plain or text/html AddDefaultCharset utf-8 # force utf-8 for a number of file formats AddCharset utf-8 .html .css .js .xml .json .rss 

你的语法看起来不错。 有些人可能会这样称呼我,但我使用apache的示例configuration显示在这里:

另外,我强烈build议把这些规则放在你的apacheconfiguration文件中,而不是放在.htaccess文件中。 这是因为当请求进来时,apache不得不寻找你的.htaccess文件,读取它们,并且dynamic地处理它们的configuration。 如果你把configuration放在主要的apacheconfiguration文件中,它会在第一次启动apache的时候编译它们。

在每秒有大量请求的非常繁忙的网站上,使用.htaccess文件可以很快地降低网站的速度。