Opened 3 years ago

Closed 3 years ago

Last modified 23 months ago

#33148 closed Cleanup/optimization (duplicate)

Set `Cache-Control: max-age=0` header on static files response so that files are easily refreshable during development

Reported by: bhch Owned by: nobody
Component: contrib.staticfiles Version: 3.2
Severity: Normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: yes UI/UX: no

Description

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. 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 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.

Change History (4)

comment:1 by Mariusz Felisiak, 3 years ago

Component: Uncategorizedcontrib.staticfiles
Resolution: duplicate
Status: newclosed

Duplicate of #33148.

in reply to:  1 ; comment:2 by bhch, 3 years ago

Replying to Mariusz Felisiak:

Duplicate of #33148.

Is this a typo? 33148 is this very ticket.

in reply to:  2 comment:3 by Mariusz Felisiak, 3 years ago

Replying to bhch:

Replying to Mariusz Felisiak:

Duplicate of #33148.

Is this a typo? 33148 is this very ticket.

Sorry, duplicate of #32891.

comment:4 by Kevin Christopher Henry, 23 months ago

This issue is being discussed in the Django Forum.

Note: See TracTickets for help on using tickets.
Back to Top