在Apache服务器上使用.htaccess实现缓存控制

TH1*_*981 6 apache .htaccess cache-control

好吧,我仍然试图了解一些缓存内容,并且我已经介绍了几个我可以在Google上找到的例子.我已将以下代码添加到我的.htaccess文件中:

### activate mod_expires
ExpiresActive On
### Expire .gif's 1 month from when they're accessed
ExpiresByType image/gif "access plus 3 months"
ExpiresByType image/png "access plus 3 months"
ExpiresByType image/jpg "access plus 3 months"
ExpiresByType text/javascript "access plus 3 months"
Run Code Online (Sandbox Code Playgroud)

使用Chrome审核工具和YSlow Firebug工具,看起来这是缓存我的一些图像/文件,但不是所有这些都是.我还有一个文件列表(.jpg,.js和.css - 我知道我没有设置要缓存的css文件),这些文件不是缓存的.Chrome审核中的消息只是说明了这一点The following resources are missing a cache expiration. Resources that do not specify an expiration may not be cached by browsers:

一些不缓存的图像是背景图像,其他图像是js图库的一部分,它们是通过JS调用的 - 这可能会影响它们不缓存的原因吗?

抱歉,我无法提供代码链接 - 这些网站仍然处于封装状态,仅限于客户端视图.

提前致谢!

小智 9

您似乎编写了错误的MIME类型:

# enable expirations
ExpiresActive On
ExpiresDefault "access plus 1 week"
ExpiresByType image/gif "access plus 1 week"
ExpiresByType image/png "access plus 1 week"
ExpiresByType image/jpeg "access plus 1 week"
ExpiresByType image/pjpeg "access plus 1 week"
ExpiresByType text/javascript "modification plus 1 week"
ExpiresByType application/javascript "modification plus 1 week"
ExpiresByType text/css "modification plus 1 week"
Run Code Online (Sandbox Code Playgroud)