Google Chrome Cache PDF files Google Chrome Cache PDF files google-chrome google-chrome

Google Chrome Cache PDF files


You really have three choices here:

  1. Change the filename everytime it gets updated
  2. Always generate the HREF with a GET parameter
  3. Send header information telling the browser to always download fresh from server

Option 1 - Works in 100% of cases. Might be tricky to maintain

echo '<a href="files/pdfs/'.$row['FILENAME_FROM_DATABASE'].'">PDF</a>';// Could produce something like:// <a href="files/pdfs/filename_v5.pdf">PDF</a>

Option 2 - Works in 99% of cases

echo '<a href="files/pdfs/filename.pdf?q='.microtime(true).'">PDF</a>';

Option 3 - Works in 99% of cases

header("Pragma: public");header("Cache-Control: maxage=1"); // <-- importantheader('Expires: '.gmdate('D, d M Y H:i:s', time()+1).' GMT');header('Content-type: application/pdf');exit(file_get_contents(PATH_TO_PDF_FILE));


In HTML5 you can force a browser not to cache for certain domains (or not to cache at all, or use cache if available and so on) - see https://developer.mozilla.org/en-US/docs/HTML/Using_the_application_cache

Add this to your <!doctype html><head> -section :

<html manifest="my.cache">

create a file on your document root - my.cache - containing the following :

CACHE MANIFEST  CACHE  # dont force any caching NETWORK:#force downloads form your site not to use cacheyour-site.com

This forces that nothing is being cached.

If you have a path to your pdf-download, use that instead (so other files from your site except the PDF's will be cached)

Try this in a browser. Remember to clear the cache first! :) When you will discover that each PDF is downloaded, regardless of filename or headers.


I would complete with a third option, by appending a dynamic parameter to the link that will download the file, ie :

    <a href="http://host.com/my_file.pdf?t=<?php time(); ?>">My File</a>

That should bypass the cache.