Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Browser Won't Request Latest PDF from Server

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?

like image 641
James Allen Avatar asked Aug 05 '14 18:08

James Allen


2 Answers

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>
like image 163
GNakano Avatar answered Sep 21 '22 09:09

GNakano


Similar to the answer by GNakano on using cache expiration per file type using .htaccess (on Apache), the following post describes how to set cache expiration per directory using web.config on IIS: How to configure static content cache per folder and extension in IIS7?

With this approach, you just need to place all .pdf and .docx in a separate folder (with no caching) and can then still have caching for your other stuff.

like image 42
tholesen Avatar answered Sep 21 '22 09:09

tholesen