title: How to prevent cached response (flask server, using chrome)
body: <p>EDIT: Figured it out, press F12, click network, check "Disable cache".</p>
  
  <p>I have a basic flask server I'm using to learn d3. The problem is that chrome is giving me a cached javascript file I'm working with, example.js.</p>
  
  <p>Request Method:GET
  Status Code:200 OK (from memory cache) </p>
  
  <p>The server itself is sending a non cached response, I can see this by looking at the response directly via:</p>
  
  <p>/static/example.js</p>
  
  <p>I added this in application.py to prevent caching.</p>
  
  <pre><code>@app.after_request
  def add_header(r):
      """
      Add headers to both force latest IE rendering engine or Chrome Frame,
      and also to cache the rendered page for 10 minutes.
      """
      r.headers["Cache-Control"] = "no-cache, no-store, must-revalidate"
      r.headers["Pragma"] = "no-cache"
      r.headers["Expires"] = "0"
      r.headers['Cache-Control'] = 'public, max-age=0'
      return r
  </code></pre>
  
  <p>Here's the entire code</p>
  
  <pre><code>import os
  import re
  from flask import Flask, jsonify, render_template, request, url_for
  from flask_jsglue import JSGlue
  
  from flask import send_file
  
  # configure application
  app = Flask(__name__)
  JSGlue(app)
  
  # prevent cached responses
  @app.after_request
  def add_header(r):
      """
      Add headers to both force latest IE rendering engine or Chrome Frame,
      and also to cache the rendered page for 10 minutes.
      """
      r.headers["Cache-Control"] = "no-cache, no-store, must-revalidate"
      r.headers["Pragma"] = "no-cache"
      r.headers["Expires"] = "0"
      r.headers['Cache-Control'] = 'public, max-age=0'
      return r
  
  @app.route("/&lt;string:filename&gt;")
  def main(filename):
      """Render file."""
      return render_template(filename)
  
  @app.route("/favicon.ico")
  def favicon():
      filename = 'images/fav.png'
      return send_file(filename, mimetype='image/png')
  </code></pre>
  
  <p>Thanks for reading.</p>