使用锚标记请求文件时强制浏览器不使用缓存 [英] Force browser to not use cache when requested for file using anchor tag

查看:107
本文介绍了使用锚标记请求文件时强制浏览器不使用缓存的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个用于请求下载文件的定位标记.

赞:

<a href="app/results?fileName=t12.txt&other-param=something" title="Click to download"> Download </a>

该文件可能经常在服务器上被修改,因此我想确保浏览器不会缓存该文件.

但是,测试人员发现,尽管当您单击链接时似乎总是下载文件,但是当您右键单击链接并选择另存为..."时,浏览器似乎选择使用而是缓存文件.这已经通过IE9进行了测试.

在每种情况下,如何强制浏览器(尤其是IE9)始终下载文件?

解决方案

根据我对以下答案之一的评论:

根据Wikipedia,我可以设置响应标头参数:Cache-Control:no-cache

http://en.wikipedia.org/wiki/List_of_HTTP_header_fields#Effects_of_selected_HTTP_header_field>/p>

在收到带有此标头的响应后,浏览器将不再缓存此数据.

I have an anchor tag that is used to request the download of a file.

Like this:

<a href="app/results?fileName=t12.txt&other-param=something" title="Click to download"> Download </a>

The file may be modified on the server very often, so I want to make sure the browser does not cache the file.

However, testers found out that, although it seems to always download the file when you click on the link, when you right-click on the link and choose "Save As...", the browser seems to choose to use the cached file instead. This was tested with IE9.

How can I force the browser (especially IE9) to always download the file in every case?

解决方案

As per my own comment for one of the answers:

According to wikipedia I can set the response header parameter: Cache-Control: no-cache

http://en.wikipedia.org/wiki/List_of_HTTP_header_fields#Effects_of_selected_HTTP_header_fields

After receiving a response with this header, the browser will not cache this data anymore.

这篇关于使用锚标记请求文件时强制浏览器不使用缓存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆