keshavv
keshavv

Reputation: 147

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

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?

Upvotes: 5

Views: 2088

Answers (3)

DTailor
DTailor

Reputation: 158

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.

Upvotes: 6

sergzach
sergzach

Reputation: 6764

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.

Upvotes: 2

Jesse the Game
Jesse the Game

Reputation: 2628

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

Upvotes: 4

Related Questions