【问题标题】:Some questions about caching关于缓存的一些问题
【发布时间】:2011-06-26 18:55:25
【问题描述】:
我正在将 apache 网络服务器用于 django 应用程序。如何为图像和 css 设置缓存?我在我的网站上运行了一个网页测试,它显示 css 和图像的“未指定过期”。但是,当我使用 Firebug 时,对于 css 文件,firebug 会显示请求和响应标头,以及在缓存选项卡中显示
设备:磁盘
并且没有显示对图像的请求。所以,我有点困惑。这里发生了什么?
【问题讨论】:
标签:
django
apache
caching
firebug
【解决方案1】:
我通常在我的 apache vhost 中有这个 django 静态文件的配置:
Alias /static/ "/home/django/projectName/static/"
<Directory "/home/django/projectName/static">
Order allow,deny
Allow from all
Options +FollowSymLinks
ExpiresActive On
ExpiresByType image/gif A1209600
ExpiresByType image/jpeg A1209600
ExpiresByType image/png A1209600
ExpiresByType text/css A1209600
ExpiresByType text/javascript A1209600
ExpiresByType application/x-javascript A1209600
<FilesMatch "\.(css|js|gz|png|gif|jpe?g|flv|swf|ico|pdf|txt|html|htm)$">
ContentDigest On
FileETag MTime Size
</FilesMatch>
</Directory>
记住不要在生产中使用 django static.serve 视图。
在 Firefox 中也可以使用 Ctrl+Shift+R 进行完全重新加载(覆盖缓存)