簡體   English   中英

在Django中緩存靜態文件

[英]Caching static files in Django

我當時使用Google的Firebug的Page Speed插件對Web應用程序的性能進行了分析,其中之一是我應該“利用緩存”-“以下可緩存資源的生存期很短。請指定至少一周的有效期將來用於以下資源”。 當我更深入地挖掘時,我發現到Django WSGI服務器的所有對靜態文件的請求都缺少ExpiresCache-Control標頭。 誰應該添加這些標頭-Django應該這樣做嗎? 如果是這樣,怎么辦?

謝謝。

您的網頁可能具有的任何靜態文件都應由Web服務器(例如Apache)提供。 除非您必須防止某些人訪問某些文件,否則Django永遠不要參與。

在這里, 我找到了一個如何做的例子

# 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>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM