In a chat with James Tauber he mentioned he needed a cachebuster and for a few projects including Pinax I need to ensure my css and javascript edits are not being cached in the browser. This is a standard feature in Rails but not in Django so I whipped up a simple setup of tag helpers to do the trick.
Introducing the stupidly simple django-cachebuster written while watching the Football Sunday. I'll probably continue to add new tags to simplify my projects. Ideas are welcome.
For now it has two helpers, css_tag and js_tag. Using the template tags will return a full css or javascript tag with the filename and a sha1 hash appended based on the name and edit date of the file. When the file is changed the hash is updated.
Usage
I didn't like the way the code blocks formatted so I'll just let you read the "Usage" over at github.









On Monday, Sep 22
According to Steve Sounders, the author of "High Performance Websites" and creator of YSlow, it's better to use the path to do this than the query string. Here's the article with the details: http://www.stevesouders.com/blog/2008/08/23/revving-filenames-dont-use-querystring/
On Monday, Sep 22
Interesting read, thanks Dan. I will definitely take that into consideration!
On Monday, Sep 22
super nice greg. I'll bet you'll see some requests come in for generating different types of css (ie. print, etc) busters and then you'll have to go beyond Django's awesomse simpletags and into more the advanced template tag. I'm going to use this on a project starting today. kudos!
On Monday, Sep 22
Yeah, i've already thought about print Kevin. Good point.
I'm also thinking about images, but they are not as much a priority as css was.
On Monday, Sep 22
Dan,
Revisiting your comment, I read through that article and that's a very good point he makes and an excellent solution for those of us who have root access to the server to make those kind of changes and additions to the config files. Thanks again!