防止IE缓存服务器响应,如何防止缓存响应(flask服务器,使用chrome)

编辑:找出原因,按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')

谢谢你的阅读。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值