I was trying to find a way to prevent browsers from caching PDF that is being loaded using a streaming methods.
FireFox and Chorme deals just fine with the following headers and doesn't cache any pdf file:
Response.AddHeader("Pragma", "no-cache, no-store"); Response.AddHeader("Cache-Control", "no-cache, no-store, must-revalidate, max-age=0"); Response.AddHeader("Expires", "-1");
Although, IE 7 (with acrobat reader 9.4.1) works only with the following headers and prevent the caching of the PDF doc:
Response.AddHeader("Pragma", "no-cache, no-store"); Response.AddHeader("Cache-Control", "private, must-revalidate, max-age=0"); Response.AddHeader("Expires", "-1");
When i was trying to use IE 7 with Acrobat Reader 10, the above header didn't make any different and cached the PDF no matter what i tried.
When i am trying to put Cache-Control: no-cache, no-store, the pdf was not loaded at all. According to my understanding, IE use the cache mechanism to load the PDF documents.
Is there anyone familiar with a global or specific way (by using other headers for example) that can help prevent caching of PDF documents?
Indeed, this happens at least in Chrome and Edge browsers. It happens because the pdf file that you pass to the viewer (iframe or PDFObject) is always cached internally with the same name. You can solve it add a random number or date and time as the name of the pdf.
PDFs can be slow because they hold too much data or contain unnecessary objects inserted by the programs that created the PDFs.
Choose “Tools” > “Protect” > “Encrypt” > “Remove Security.” Remove Security: The options vary depending on the type of password security attached to the document. If the document has a Document Open password, click “OK” to remove it from the document.
Add a random number to the URL, either in the path or in the query string. That way, it'll download the file every time. You could also change the number only, if the file has changed, for example using the mtime of the file.
PHP (since everybody understands that, even if nobody likes it):
<a href="document.pdf?buster=<?= time() ?>">Download PDF</a>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With