问题
I have python-django site which contains css and js files. For every time of updating/adding css or js have to clear the cache of the browser then only its reflect in browser.
Is the any specific way to do avoid every time cache clear and check?
Is there any specific settings available in django to avoid storing browser cache?
回答1:
Use this small 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
回答2:
You could just append something to the updated js/css file, like this. For example versioning "?v=1.0".
<link rel="stylesheet" type="text/css" href="{{ STATIC_URL }}_css/style.css?v=1.6">
So this way, every time the browser detects a change, it will automatically fetch the new file. Simple and clean.
回答3:
If you use a browser.
Yes. You can use the hot keys: Ctrl + F5 (instead of F5). It will clear the cache automatically when you update a page.
来源:https://stackoverflow.com/questions/13487612/dont-want-to-clear-browser-cache-on-every-time-for-css-js-updates