Skip to main content

Django 1.3 ready cache busting app

Project description

Overview

django-cachebuster is a Django app containing two template tags: static and media. Each tag will use the file last modified timestamp by default to ‘bust’ web browser file caches. static is meant for your site’s JavaScript, CSS and standard images. media is intended for user uploaded content like avatars, videos and other files.

Description

All of the existing file cache busting techniques seem to be Django versions 1.2.x and lower oriented - meaning they don’t support the new django.contrib.staticfiles paradigm. This app addresses this functionality gap.

Additionally, there are some optimizations (see Advanced Settings below) that can be enabled to minimize file modification date disk reads.

Requirements

  • Python 2.6 (May work with prior versions, but untested - please report)

  • Django 1.2.x, 1.3.x (May work with prior versions, but untested - please report)

Installation

  1. Copy or symlink the cachebuster package into your django project directory or install it by running one of the following commands:

    python setup.py install

    or

    pip install django-cachebuster

    or

    easy_install django-cachebuster

  2. Add cachebuster to your INSTALLED_APPS in your project’s settings.py module.

  3. Use the {% static filename %} and {% media filename %} tags in your template files.

Advanced Settings

CACHEBUSTER_UNIQUE_STRING: optional; no default.

If CACHEBUSTER_UNIQUE_STRING is not set, the file’s last modified datetime will be used for cache-busting. To set it, you would mostly likely use a cachebuster detector; at the moment, there is a single detector available for git. It simply traverses the project’s path looking for the .git folder, and then extracts the current commit hash. The hash is cached and used for subsequent cache-busting. For example, in your settings.py:

from cachebuster.detectors import git
CACHEBUSTER_UNIQUE_STRING = git.unique_string()

or if you wanted it to be a short busting string:

from cachebuster.detectors import git
CACHEBUSTER_UNIQUE_STRING = git.unique_string()[:8]

Notes

Please feel free to send a pull request with fixes and in particular, additional detectors to improve the usefulness of this app. Maybe for svn, hg, etc?

Source

The latest source code can always be found here: github.com/jaddison/django-cachebuster

Credits

django-cachebuster is maintained by James Addison.

License

django-cachebuster is Copyright (c) 2011, James Addison. It is free software, and may be redistributed under the terms specified in the LICENSE file.

Questions, Comments, Concerns:

Feel free to open an issue here: github.com/jaddison/django-cachebuster/issues

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django-cachebuster-0.1.tar.gz (2.6 kB view details)

Uploaded Source

File details

Details for the file django-cachebuster-0.1.tar.gz.

File metadata

File hashes

Hashes for django-cachebuster-0.1.tar.gz
Algorithm Hash digest
SHA256 63bdc13c56a906f9d386768c2033b3f2d591c3eb95c399e3aa61c42a1005fd43
MD5 30fb5e382fd5b1dc72d07bee1cb8591b
BLAKE2b-256 fbc6db87b7d8fce153481d00de136f0a4ca614a82e5dd8940b270091951e38fc

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page