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?