关于缓存的一些问题

时间:2011-02-14 08:47:57

标签: django apache caching firebug

我正在使用apache webserver用于django应用程序。如何为图像和CSS设置缓存?我在我的网站上运行了一个网页测试,并为css和图像显示“未指定过期”。但是,当我使用Firebug时,对于css文件,firebug显示请求和响应标头,以及在缓存选项卡中显示

设备:磁盘

并且没有针对图像显示请求。所以,我有点困惑。这里发生了什么。?

1 个答案:

答案 0 :(得分:2)

我通常在我的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视图。

还可以使用Ctrl + Shift + R在Firefox中执行完全重新加载(覆盖缓存)

相关问题