编辑:找出原因,按F12,单击网络,选中“禁用缓存”。
我有一个基本的烧瓶服务器,用来学习d3。问题是chrome给了我一个正在使用的缓存javascript文件example.js。
请求方法:GET
状态代码:200 OK(来自内存缓存)
服务器本身正在发送一个非缓存响应,我可以通过以下直接查看响应:
/static/example.js/静态/example.js
我在application.py中添加了这个以防止缓存。@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
这是全部代码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("/")
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')
谢谢你的阅读。