在这里搜索 SO 会返回一些很好的信息 - 例如 Leverage browser caching - 但无论如何......
发件人:http://www.samaxes.com/2011/05/improving-web-performance-with-apache-and-htaccess/
第一次访问您的页面的访问者会发出多个 HTTP 请求来下载您的所有站点文件,但通过使用 Expires 和 Cache-Control 标头,您可以使这些文件可缓存。这样可以避免在后续页面查看时发出不必要的 HTTP 请求。
借助 mod_expires 和 mod_headers 模块,Apache 启用了这些标头。
mod_expires 模块控制服务器响应中Expires HTTP 标头和Cache-Control HTTP 标头的max-age 指令的设置。
要修改max-age以外的Cache-Control指令,可以使用mod_headers模块。
mod_headers 模块提供指令来控制和修改 HTTP 请求和响应标头。标题可以合并、替换或删除。
Expires标头设置规则:
# BEGIN Expire headers
<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>
# END Expire headers
Cache-Control 标头设置规则:
# BEGIN Cache-Control Headers
<ifModule mod_headers.c>
<filesMatch "\.(ico|jpe?g|png|gif|swf)$">
Header set Cache-Control "public"
</filesMatch>
<filesMatch "\.(css)$">
Header set Cache-Control "public"
</filesMatch>
<filesMatch "\.(js)$">
Header set Cache-Control "private"
</filesMatch>
<filesMatch "\.(x?html?|php)$">
Header set Cache-Control "private, must-revalidate"
</filesMatch>
</ifModule>
# END Cache-Control Headers
注意:不需要使用Cache-Control 标头设置max-age 指令,因为它已经由mod_expires 模块设置。
must-revalidate 意味着一旦响应变得陈旧,就必须重新验证;这并不意味着每次都必须检查。
更多信息在这里:http://www.mnot.net/cache_docs/
来自谷歌:http://code.google.com/speed/page-speed/docs/caching.html
和雅虎:http://developer.yahoo.com/performance/rules.html#expires