【发布时间】:2018-01-22 04:19:04
【问题描述】:
我在 IE 浏览器中遇到缓存问题。我的网页具有下载 pdf 功能。服务器提供文件内容,然后将其作为 blob 对象进行操作,然后输入到 filesaver.js。每次我下载 pdf 时,都会显示旧文件。我怎样才能防止这种情况发生?
我尝试在文件名中附加随机数。缓存问题仍然存在。
var pdfFileName ="myfile" + "_" + i; // i=0,1,2,3 etc
var fileName = new Blob([response], {
type: 'application/pdf'
});
saveAs(file, pdfFileName + ".pdf");
另一种有效的方法是从 IE 设置 -> Internet 选项 -> 常规选项卡 -> 浏览历史记录 - 设置 -> 选择“每次访问网页时”选项。这帮助我消除了缓存问题。
但我想知道如何以编程方式处理缓存?
【问题讨论】:
-
展示你如何
tried to append random numbers with the file name- 因为这听起来像是一种方法 -
让服务器告诉浏览器不要缓存文件通过配置正确的响应头伴随下载,例如stackoverflow.com/a/13640164/246342
-
@Jaromanda X 我已经用你问的代码更新了这个问题。当我单击“保存”按钮时,生成的文件名如 myfile_0、mfile_1 等
标签: javascript jquery angularjs html caching