Flask url_for() no cache Flask url_for() no cache flask flask

Flask url_for() no cache


I wrote a blog post about this a while ago.

Basically, you need to create a response to send, then set some extra headers on the response, then send the response:

def send_url(method):    response = app.make_response(url_for(method))    response.headers.add('Last-Modified', datetime.datetime.now())    response.headers.add('Cache-Control', 'no-store, no-cache, must-revalidate, post-check=0, pre-check=0')    response.headers.add('Pragma', 'no-cache')    return response


Disabling all caching just because once in a while you have a new release is really not good practice. Caching of css and js gives huge performance benefits.

What good sites do is to add a timestamp of the file to the resource URLs. For example, in Flask, here is a way to do this transparently: http://flask.pocoo.org/snippets/40/