Flask static file Cache-Control Flask static file Cache-Control flask flask

Flask static file Cache-Control


You may want to look at webassets to manage the cache expiry. It works in both development and production environment.


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.