20seven

Devigner blog about development and design

Django Cachebuster

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.