django-cachekiller
django-cachekiller is a small add-on for Django that adds the cdnstatic
template tag which adds a 'cache busting' dynamic query string appended to the
file paths. This tag functions identically to the standard {% static ... %}
template tag. This is designed to work with CDNs that cache by complete URI
including the query string so when you push a change the CDNs are automatically
refreshed without having to wait for TTLs to expire. Internally we use this with
django-distill, a static site generator for Django to work with static sites
with heavy caching on images behind CloudFlare, cachefly and other CDNs:
https://github.com/meeb/django-distill
Under the hood, this module just chains the request to the existing static tag
to be widely compatible.
Installation
Install from pip:
$ pip install django-cachekiller
Add django_cachekiller to your INSTALLED_APPS in your settings.py:
INSTALLED_APPS = [
# ... other apps here ...
'django_cachekiller',
]
That's it.
Usage
Load the new module at the top of your templates:
{% load cdnstaticfiles %}
Then use the new tag in the template exactly as you would use the static tag:
{% cdnstatic 'some/image.jpg' %}
This renders as (assuming settings.STATIC_URL is set to /static/):
/static/some/image.jpg?tag=[random tag]
[random tag] is either the truncated mercurial or git commit reference if it
is available, otherwise it will be the current date in YYYYMMDDHHMMSS format.
If there are existing query string parameters then the tag is intelligently
appended. The cdnstatic tag will not break the existing URL.
Additionally, if you need to just access the [random tag] for some other use
without the automatic URL rewriting you can use the following:
<a href="/someurl.html?tag={% cdntag %}">link</a>
This can be used in conjunction with other URL wrapping tags for combatability where chaining tags is difficult, for example:
<link rel="stylesheet" href="{% sass_src 'file.scss' %}?tag={% cdntag %}">
Contributing
All properly formatted and sensible pull requests, issues and comments are welcome.
Metadata
Release files for django-cachekiller 0.8.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| django-cachekiller-0.8.2.tar.gz | 4.0 kB | Details |
Release files / django-cachekiller-0.8.2.tar.gz
| Download URL | django-cachekiller-0.8.2.tar.gz |
|---|---|
| Size | 4.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
72cdc10889424ddfe15aa5670ed27c1aa2592a9edf0b9302454d4f74080b73e0
|
|
BLAKE2b-256 checksum How to use checksums |
07f06f8805a082f4cd16da17c2c27915a8db6320f17955579aa33d2e0dfc0040
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.1.1 pkginfo/1.4.2 requests/2.22.0 setuptools/45.2.0 requests-toolbelt/0.8.0 tqdm/4.30.0 CPython/3.8.10
|