1

I am having caching issue in IE browser. My web page has download pdf functionality. The server provides the file contents which is then manipulated as a blob object and then inputted to filesaver.js.Each time I download a pdf the older file is being shown. How can I prevent this?

I tried to append random numbers with the file name. Still the cache issue existed.

var pdfFileName ="myfile" + "_" + i; // i=0,1,2,3 etc
var fileName = new Blob([response], {
               type: 'application/pdf'
 });
saveAs(file, pdfFileName + ".pdf");

Another approach which worked is from IE Settings -> Internet Options -> general tab -> Browsing history - Settings -> Select the option "Every time I visit the webpage". This helped me to eliminate the cache issue.

But I want to know how to handle caching programmatically?

srkm
  • 11
  • 5
  • Show how you `tried to append random numbers with the file name` - because that sounds like one way to do it – Jaromanda X Aug 14 '17 at 10:36
  • Make the server tell the browser not to cache the file by configuring the correct response headers that accompany the download, E.g. https://stackoverflow.com/a/13640164/246342 – Alex K. Aug 14 '17 at 10:41
  • @Jaromanda X I have updated the question with the code you asked. When I click the SAVE button file name were generated like myfile_0,mfile_1 etc – srkm Aug 14 '17 at 11:41

1 Answers1

1

Appending random integer while saving file will not work. Append it in url, when you try to retrieve pdf as blob from server.