Don't want to clear your browser cache every time for css / js updates

I have a python-django site that contains css and js files. For each update / addition of css or js, it is necessary to clear the browser cache, but only its reflection in the browser.

Is there any specific way to avoid explicit cache flushing and validation?

Are there any specific settings in django to avoid storing the browser cache?

+4
source share
3 answers

Use this little middleware

from django.utils.cache import add_never_cache_headers class NoCachingMiddleware(object): def process_response(self, request, response): add_never_cache_headers(response) return response 
+3
source

You can just add something to the updated js / css file like this. For example, the version is "? V = 1.0".

 <link rel="stylesheet" type="text/css" href="{{ STATIC_URL }}_css/style.css?v=1.6"> 

Thus, every time the browser detects a change, it automatically retrieves a new file. Simple and clean.

+5
source

If you are using a browser.

Yes. You can use hotkeys: Ctrl + F5 (instead of F5). It will clear the cache automatically when the page is refreshed.

+1
source

Source: https://habr.com/ru/post/1447410/


All Articles