Search code examples
djangooffline-cachingdjango-mediagenerator

Where to set cache headers for manifest file on django app?


I'm using django mediagenerator to compress and setup for offline and it is mostly working, but when I regenerate the media files (which updates the manifest file) the browser does not notice that it has changed so reads the old manifest which references files that are not longer there (as mediagenerator gives them new names each time they are regenerated) so it fails. From my reading it seems this is because the browser is cacheing the manifest file so it hasn't noticed that it has changed. So how do I persuade it not to?

This is a VPS so I can change the apache settings or is there something in django I should be doing?


Solution

  • In case anyone else has this problem, here is how I resolved it. Instead of going direct to the template from urls.py, I used a view like this:

    from django.views.decorators.cache import cache_control
    
    
    @cache_control(must_revalidate=True, max_age=60*60*24)
    def home(request):
    
        return render_to_response("index.html", {
    
            },
            context_instance=RequestContext(request)
        )
    

    Now updates to my static files are being recognised.