2010-10-21 87 views
4

我使用Google的Firebug的Page Speed插件分析了我的web应用程序的性能,它说的其中一件事是我应该“利用缓存” - “以下可缓存资源的新鲜度寿命。为以下资源指定至少一周的到期日期“。当我深入挖掘时,我发现所有对Django WSGI服务器的静态文件请求缺少ExpiresCache-Control标题。谁应该添加这些头文件 - Django应该这样做?如果是这样,怎么样?在Django中缓存静态文件

谢谢。

+0

静态文件应由要么阿帕奇/ lighthttpd/...你使用什么都Web服务器提供服务... – shahjapan 2010-10-21 06:53:52

回答

7

您的网页可能具有的任何静态文件都应由您的网络服务器提供,例如, Apache的。除非必须阻止某些文件访问某些人,否则Django不应该参与其中。

这里,I found an example of how to do it

# our production setup includes a caching load balancer in front. 
# we tell the load balancer to cache for 5 minutes. 
# we can use the commented out lines to tell it to not cache, 
# which is useful if we're updating. 
<FilesMatch "\.(html|js|png|jpg|css)$"> 
ExpiresDefault "access plus 5 minutes" 
ExpiresActive On 
#Header unset cache-control: 
#Header append cache-control: "no-cache, must-revalidate" 
</FilesMatch>