Browser Won't Request Latest PDF from Server

James Allen picture James Allen · Aug 5, 2014 · Viewed 9.6k times · Source

I have a PDF on Windows Server IIS web server, where users request it with IE8/9/10 using HTTP call like this...

http: // mydomain.com / somefolder / myFile.pdf

First hit will download the file no problem. Problem: if admin updates the PDF, and user goes back to reload it, IE only shows local cached version and will NOT request a new version from the server.

I have confirmed that on 2nd request, IE8, IE9, and IE10 do not call the server at all for the PDF file. Not even a conditional request (e.g., if-updated-since). Confirmed this using Fiddler and WireShark. But I never explicitly set the caching with Max-Age or anything. I have no caching set for that folder. I would prefer not to set cache to "expire immediately". It does this for Word DOC's also.

Is there a bug in Internet Explorer that makes it ALWAYS use local copies of static docs (e.g., PDFs, DOCs) no matter what?

These ideas do NOT work:

  1. F5, CTRL+F5, SHIFT+F5

  2. Clear the browser history and cache using the DELETE HISTORY button. Why this actually doesn't clear ALL the cache is beyond me. I have everything selected for deletion except passwords.

The only ways I know around this are:

  1. Manually delete the PDF locally because the "DELETE HISTORY" button does not delete the local version. But most users are not that savvy.

  2. Use Firefox but that's not a company-approved browser. Don't get me started.

  3. Set server caching to Expire Immediately, but pdfs are mixed in folders with web pages and I prefer not to do this. I want to use caching max age for other things like CSS, scripts, images, etc..

  4. Add a fake query string to the end like ?id=1, and that works, but the business line has 100's of docs each with links inside the docs that would have to be updated.

  5. Use FIDDLER "clear cache" button or CCleaner, but most users in my company (70k employees) are not developers and can't have that software.

Is there a real solution for this, to make IE behave like I thought it would?

Answer

GNakano picture GNakano · May 16, 2015

I was able to change the htaccess file to add an age to the cache of pdf files. This worked perfectly for fixing this issue on IE and other browsers where a refresh or reopen of the browser fixed the problem.

# Requires mod_expires to be enabled.
<IfModule mod_expires.c>
  # Enable expirations.
  ExpiresActive On

<FilesMatch ".(pdf)$">
  Header set Cache-Control "max-age=0"
</FilesMatch>

</IfModule>