#33148: Set `Cache-Control: max-age=0` header on static files response so that
files are easily refreshable during development
------------------------------------------------+------------------------
Reporter: bhch | Owner: nobody
Type: Cleanup/optimization | Status: new
Component: Uncategorized | Version: 3.2
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 1
UI/UX: 0 |
------------------------------------------------+------------------------
**Problem**
Currently, the view (`django.views.static.serve`) which serves static
files in development only sets a `Last-Modified` header.
The problem this produces is that Firefox and Chrome don't send the cache
revalidation requests (`If-Modified-Since` header), and will keep on
serving stale files even after modifications.
[https://engineering.fb.com/2017/01/26/web/this-browser-tweak-saved-60-of-
requests-to-facebook/, Here's a good article on this from Facebook
Engineering].
So, during development, when we make changes to the static files (CSS/JS),
we need to open the `Network` tab and disable the cache to refresh the
static files.
On Mobile, disabling cache is not possible so we have to test in Incognito
mode.
**Solution**
Set `Cache-Control: max-age=0` header on the response.
As per [https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Cache-
Control#requiring_revalidation this MDN page on Cache-Control] and some
tests I did on my computer, browsers can be forced to revalidate the cache
using `Cache-Control: max-age=0` header.
This will force the browsers to send the `If-Modified-Since` header and
Django can then send a 304 response if unmodified or serve the fresh file
if modified.
--
Ticket URL: <https://code.djangoproject.com/ticket/33148>
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 view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/047.9ffe06420478b74830466884bc6e34ca%40djangoproject.com.