Opened 8 years ago

Closed 8 years ago

Last modified 22 months ago

#27572 closed Cleanup/optimization (wontfix)

Static files served in development should prevent caching — at Version 4

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

Description (last modified by Mateusz Kurowski)


Change History (4)

comment:1 by Tim Graham, 8 years ago

We've been thinking about replacing our own staticfile serving code with something like whitenoise (#27572). Do you know if it has a suitable option?

Last edited 8 years ago by Tim Graham (previous) (diff)

comment:2 by Kevin Christopher Henry, 8 years ago

I haven't used whitenoise before, but based on the documentation it looks like it's already doing what I proposed above:

WHITENOISE_MAX_AGE
    Default: 60 if not settings.DEBUG else 0

Time (in seconds) for which browsers and proxies should cache non-versioned files.

So, yes, a switch to whitenoise should solve this problem! I don't know how imminent that is, so I'll leave it up to you whether this is worth fixing in the meantime.

comment:3 by Tim Graham, 8 years ago

Resolution: wontfix
Status: newclosed

Great, I don't see much value in duplicating work then.

comment:4 by Mateusz Kurowski, 22 months ago

Description: modified (diff)

For future reference here is a monkey patch that works for me in development:

from functools import wraps

import django.http
import django.views.static


def no_cache_static(f):
    @wraps(f)
    def static(*a, **kw):
        response: django.http.response.HttpResponse = f(*a, **kw)
        response.headers["Cache-Control"] = "no-cache"
        return response

    return static


django.views.static.serve = no_cache_static(django.views.static.serve)

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