2đź‘Ť
It would be better to use the last modification timestamp of the file. Then you would avoid the problems you would run into with the version number. You would also either have to go to disk on every request to get the latest revision number(use cache if using this approach) or change your include statements in a “compile” step when deploying.
Also, if you do styles.css?123
some proxies/browsers might not cache the file at all regardless of expiration headers. It is better to do styles.123.css
, which all agents treat as a separate file.
There is a project that already solves this problem, which I’ve used myself to great success: django-compress. You tell it how you want to compress your javascript and css, then it will minify/compress, join them together into one big file and give the big file a special filename that includes the timestamp. You also get a template tag to use when including the files that knows which file to include.
Django 1.3 will also include an app called staticfiles which helps with serving up static media, but it does not solve the problem of versioning.
0đź‘Ť
One technique I’ve used in the past is to ensure I use a template tag for every static asset reference. Then I can change that tag as required, both if I need to change the URL to the asset directories, but also so I can add cachebusting as required.
I wouldn’t worry about forcing an unnecessary fetch for each SVN revision even if the file hasn’t changed – it’s still more efficient than serving a new one each time.
There are various libraries that do this sort of thing for you. knutin has already mentioned django-compress, there’s also django-static-management, django-static and probably lots of others. In addition to dealing with cachebusting, these apps usually include some sort of compression/concatenation so that multiple CSS or JS files are concatenated into one to reduce HTTP requests.
- [Answered ]-Django Broken Pipe Error
- [Answered ]-Django self-referential foreign key with related_name doesn't work
- [Answered ]-Django app with long running calculations