I\'m working on some universal solution for problem with static files and updates in it.
Example: let\'s say there was site with /static/styles.css
file - a
The major advantage of this solution: you dont have to modify anything in the templates.
This will add the build version into the STATIC_URL
, and then the webserver will remove it with a Rewrite
rule.
settings.py
# build version, it's increased with each build
VERSION_STAMP = __versionstr__.replace(".", "")
# rewrite static url to contain the number
STATIC_URL = '%sversion%s/' % (STATIC_URL, VERSION_STAMP)
So the final url would be for example this:
/static/version010/style.css
And then Nginx has a rule to rewrite it back to /static/style.css
location /static {
alias /var/www/website/static/;
rewrite ^(.*)/version([\.0-9]+)/(.*)$ $1/$3;
}