How to Prevent Caching When using PDF Streaming with Acrobar Reader 10.0 (HTTP1.0/HTTP1.1)

Niv picture Niv · Jan 18, 2011 · Viewed 18.5k times · Source

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?

Answer

iGEL picture iGEL · Jul 12, 2012

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>