2011-01-06 64 views
6

好的,我仍然试图解决一些缓存问题,并且经历了一些我可以在Google上找到的例子。我已经添加下面的代码到我的.htaccess文件:在Apache服务器上使用.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" 

使用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" 
+0

要把这一个尝试,看看如果这样做了。谢谢!! – TH1981 2011-04-14 12:55:21

相关问题