Force browser to not use cache when requested for file using anchor tag

风流意气都作罢 提交于 2019-12-07 08:08:44

问题


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?


回答1:


I'll add as an answer. Try adding a random number to the query part of the href:

?param=[random]



回答2:


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.



来源:https://stackoverflow.com/questions/10274591/force-browser-to-not-use-cache-when-requested-for-file-using-anchor-tag

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!