I was scratching my head when the three magic meta
didn't work in Firefox and Safari.
<meta http-equiv="Cache-Control" content="no-cache, no-store, must-revalidate" />
<meta http-equiv="Pragma" content="no-cache" />
<meta http-equiv="Expires" content="0" />
Apparently it can happen because some browsers will ignore the client side meta
, so it should be handled at server side.
I tried all the answers from this post for my class based views (django==1.11.6
). But referring to answers from @Lorenzo and @Zags, I decided to write a middleware which I think is a simple one.
So adding to other good answers,
# middleware.py
class DisableBrowserCacheMiddleware(object):
def __init__(self, get_response):
self.get_response = get_response
def __call__(self, request):
response = self.get_response(request)
response['Pragma'] = 'no-cache'
response['Cache-Control'] = 'no-cache, no-store, must-revalidate'
response['Expires'] = '0'
return response
# settings.py
MIDDLEWARE = [
'myapp.middleware.DisableBrowserCacheMiddleware',
...