Google Chrome Cache PDF Files

I created a small internal PHP / MySQL application for placing and sorting documents. Everything works fine until it comes to updating the file, in this case a .PDF file. When the user updates .PDF, the new file is on the server, as expected, and the old version will be deleted. The user receives a new version because he never opened the old version.

Now the problem is .... If the user opened an older version of .PDF at some point in the past, they don’t get a newer version when they click the link to view the document, although only the new version is actually physically on the server.

I guess Google Chrome Browser caches an older version of PDF somewhere. How can I get around this? Due to the number of users and the number of times per day, some of the documents are updated so that users can manually clear the cache, this is not practical.

+4
source share
3 answers

You really have three options:

  • Changing the file name with every update
  • Always generate HREF with GET parameter
  • Send header information telling the browser that it always loads from the server

Option 1 - works in 100% of cases. It can be difficult 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>';

3 - 99%

header("Pragma: public");
header("Cache-Control: maxage=1"); // <-- important
header('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));
+13

HTML5 ( , , ..) - . https://developer.mozilla.org/en-US/docs/HTML/Using_the_application_cache

<!doctype html><head>:

<html manifest="my.cache">

- my.cache - :

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

.

pdf-, ( , PDF )

. !:) , PDF , .

+2

, , , :

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

.

0

All Articles