2011-02-14 71 views
0

我正在使用apache webserver作为django应用程序。如何设置图像和css的缓存?我在我的网站上运行了一个webpagetest,并且它对css和图像显示“到期未指定”。但是,当我使用Firebug,对CSS文件,萤火虫显示请求和响应头,以及在高速缓存标签就说明有关缓存的一些问题

设备:磁盘

,并不再要求显示了图像。所以,我有点困惑。这里发生了什么事。?

回答

2

我通常有这样的配置Django的静态文件在我的Apache虚拟主机:

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中完成重新加载(覆盖缓存)