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

老子叫甜甜 提交于 2021-01-27 06:25:53

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!