#29277: Add a bust_browser_cache flag to the static template tag
-------------------------------------+-------------------------------------
Reporter: David | Owner: nobody
Kerkeslager |
Type: New | Status: new
feature |
Component: Template | Version: 2.0
system | Keywords: browser-cache-
Severity: Normal | busting static-files
Triage Stage: | Has patch: 0
Unreviewed |
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-------------------------------------+-------------------------------------
The proposal is to add a `bust_browser_cache` flag to the `static`
template tag using a similar syntax to passing context variables to the
`include` template tag. It would look something like this:
{{{
{% static 'css/style.css' with bust_browser_cache=True %}
}}}
The flag would default to `False` to avoid breaking existing usages of the
`static` tag.
What flag does is add a `cache_hash` get parameter to the URL of the
static file, with a hash of the static file. So if the content of
`css/style.css` looks like:
{{{
p {
color: magenta;
}
}}}
The generated URL will look like
`/static/css/style.css?cache_hash=0756793258f5ea00cda3e445de6bb595`.
If the content of `css/style.css` changes to:
{{{
p {
color: magenta;
}
p::after {
content: "Sorry about this awful color.";
}
}}}
Then the link would be
`/static/css/style.css?cache_hash=c3aebd6286841ce8f4d76aa8d3eba487`.
This is not a security feature, so I think it would be best to use MD5
because it is fast.
Instead, the purpose of this is to allow us to serve static files with
`Cache-Control: immutable` or `Cache-Control: max-age=<some large number>`
without fear. As long as the content of the file does not change, the
URL's `cache_hash` will not change, so the browser will use the cached
version. But if the content of the static file changes, the `cache_hash`
parameter will change, causing the browser to request the new version of
the file. This gets us the best of both worlds: we maximize usage of
browser cache for static files, while never having to worry that our users
are seeing stale versions of static files.
--
Ticket URL: <https://code.djangoproject.com/ticket/29277>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/054.144fd1f2caac45306f659bf222784a6d%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.