Enable pdf caching in IE
At first, caching didn't work in all browsers. Then I made it work in all browsers but IE (IE8) by adding .pdf extension to the url. Servlet stopped being called after that.
I display pdf file inline on the webpage via EMBED tag that loads the following url:
Which is generated by java servlet with the following headers:
response.addHeader("Content-Disposition", "inline;"); response.setHeader("Cache-control", "cache,max-age=600"); response.setContentType(mimeType); response.setContentLength(contentLength);
For pdf displaying in all browsers I use Adobe Reader 9.2.0.
How to make it work in IE too? I noticed that IE adds 'Cache-Control: no-cache' header to request, whereas Safari, for example, doesn't.
As said before, the
cache-control header value
cache is invalid. Use
As to IE not adhering the server-side cache control rules in the
object elements, this is unfortunately a "feature" of IE. Best what you can do is replacing it by an
Other headers like
etag and so on ain't going to help.
Risposta num. 1
Some ideas to look into:
I don't think
cacheis a valid
Try using a value of
privateif that's more appropriate to your content. Check out RFC 2616 for more information.
Perhaps you're sending more than one
Use a tool like Firebug or LiveHTTPHeaders to peek at the actual headers your browsers are receiving. Make sure they're not getting something you don't expect. It sounds like you might already be doing this though. Also make sure you're not also sending
Try setting the
Expiresheader in addition to using
It's also possible you're sending the browser conflicting
Pragmaheaders and IE chooses to take the
Pragmaheaders as first priority for whatever backwards reason.
Make sure IE is configured to allow caching! :)
Temporary Internet Files>
Check for newer versions of stored pages
Try sending the PDF as a response to a
POSTrequest (via form submit).
IE is allowing a cache to take place regardless of the headers in the response due to this requirement from RFC 2616: "By default, a response is cacheable if the requirements of the request method, request header fields, and the response status indicate that it is cacheable." Responses to
POSTrequests are NOT cacheable, so IE shouldn't include that header in it's request.
Try sending the
Last-Modifiedheaders with consistent values (if they're not already being sent).
This might help convince IE that the content of the PDF has not changed. I don't think this solution will work, because IE is obviously stubborn, but it's worth mentioning.
Risposta num. 2
Well, one obvious way around the problem is to use URL rewriting. If IE works with .pdf in the extension, use mod_rewrite (Apache) or a similar tool to server-side redirect to the right page, while making the client think that it's indeed requesting a PDF file.
Also: review the HTTP headers that the client is receiving using a tool like Fiddler.
Also: review this older question (PHP: Force file download and IE, yet again), I've had similar problems with IE not forcing downloads, too.