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.
* status: new => closed
* resolution: => duplicate
* component: Uncategorized => contrib.staticfiles
Comment:
Duplicate of #33148.
--
Ticket URL: <https://code.djangoproject.com/ticket/33148#comment:1>
Comment (by bhch):
Replying to [comment:1 Mariusz Felisiak]:
> Duplicate of #33148.
Is this a typo? 33148 is this very ticket.
--
Ticket URL: <https://code.djangoproject.com/ticket/33148#comment:2>
Comment (by Mariusz Felisiak):
Replying to [comment:2 bhch]:
> Replying to [comment:1 Mariusz Felisiak]:
> > Duplicate of #33148.
>
> Is this a typo? 33148 is this very ticket.
Sorry, duplicate of #32891.
--
Ticket URL: <https://code.djangoproject.com/ticket/33148#comment:3>
Comment (by Kevin Christopher Henry):
This issue is being discussed in the [https://forum.djangoproject.com/t
/static-files-served-in-development-should-not-be-cached/18579 Django
Forum].
--
Ticket URL: <https://code.djangoproject.com/ticket/33148#comment:4>