du532861657 2016-08-01 07:40
浏览 144

即使响应具有无缓存头,文件也会被浏览器缓存

var epoch = time.Unix(0, 0).Format(time.RFC1123)
var headers = map[string]string{
    "Expires":         epoch,
    "Cache-Control":   "no-cache, private, max-age=0",
    "Pragma":          "no-cache",
    "X-Accel-Expires": "0",
}

log.Errorln("no cache header")
for k, v := range headers {
    rw.Header().Set(k, v)
}

http.ServeFile(rw, req, path)

I have the above code block in my server side to serve file requests. But the files served are still cached in browser.

But instead of http.ServeFile() I used http.ServeContent() with the last modified timestamp as time.Now(). This works if the request has considerable time difference. Does browser give priority to last modified time than no-cache header? Then what is the purpose of no-cache header? Am I doing anything wrong?

  • 写回答

1条回答 默认 最新

  • dqlxtv1452 2016-08-01 08:45
    关注

    Some browsers cache files without paying attention to headers. Typical solution is to add some get parameter to static file path, so the browser considered it like different request. It can be hash-sum or last modified timestamp. It might look somethind like this: site.com/icon.png?q=123456.

    评论

报告相同问题?

悬赏问题

  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂