Flask static file Cache-Control

后端 未结 2 1126
孤街浪徒
孤街浪徒 2021-01-03 21:03

I\'m trying to set a reasonable cache expiry for my JS files while in development. I have the standard setup, where HTML, CSS and JS are living under the static

2条回答
  •  梦毁少年i
    2021-01-03 21:37

    I had this problem and couldn't find an answer online that worked for me.

    Then I realised that my static files are not being served from Flask at all! Flask only generates my HTML. The static files are served directly by my web server (Apache in my case, yours might be Nginx or something else).

    Here are the instructions for Apache.

    First install the mod_expires module:

    sudo a2enmod expires

    Then add something like this to your .htaccess file:

    ExpiresByType text/css "access plus 1 year"
    ExpiresByType application/javascript "access plus 1 year"
    ExpiresByType image/* "access plus 1 year"
    

    More details on how to configure it in the Apache manual.

提交回复
热议问题