2

We have a website (pure html/js/css). In our site pages, we have links to PDF files, these links looks like this: <a href="../files/myFile.pdf">My file link</a>. So, the problem: sometimes we need to update our PDFs. We update these files, then go to the website, press the link - and we see old file. Ctrl+F5, or F5 in Firefox - and we see updated file. It is not good. I think that this problem caused by caching.
In our site pages (html pages, which contain links), we added such tags:

 <meta http-equiv="Cache-Control" content="no-cache, no-store, must-revalidate"> <meta http-equiv="Pragma" content="no-cache"> <meta http-equiv="Expires" content="0"> 

But it does not help. How can we avoid client-side caching? I read some questions here. This solution had been taken from stackoverflow) Also I know about adding random parameter into page URL, but some guys say that it is bad way.
Please, help with this problem. Can we avoid client-side caching only with JS? Maybe it is possible with .htaccess file on server side, but we have no access there.

3
  • That should prevent caching You could use linking to your docs with sample.doc?abc and replace the abc with random garbage. Commented Feb 4, 2020 at 9:09
  • Thanks for your response, but I wrote that it is not good solution. And where is a problem: on page caching or file caching? I suppose that it is in page: because link text is old. Am I right? Commented Feb 4, 2020 at 9:11
  • No, it does not. Sure, if user press F5, link will be updated. The problem is: when user opens site, watches our page with link (for instance, Page1), closes tab in browser, this page goes into cache. We update file. User opens our Page1 again - and it contains old link. F5 - and it contains new link. How can we avoid this F5 pressing?) Because sometimes user doesn't know that he must press F5. Commented Feb 5, 2020 at 14:34

1 Answer 1

1

You can disable caching in the Nginx or Apache web server:

 location /pdf_file_location { root /your/site/public; index index.html; # kill cache add_header Last-Modified $date_gmt; add_header Cache-Control 'no-store, no-cache, must-revalidate, proxy-revalidate, max-age=0'; if_modified_since off; expires off; etag off; } 

More informations about this you can read here

Or in the simplest way, add a variable parameter to the URL(you can generate sequence, timestamp, fixed version of the file or any other random value):

<a href="../files/myFile.pdf?v=1580807492744">My file link</a> 

?v=1580807492744 - if the value changes, the cache will not work

Sign up to request clarification or add additional context in comments.

8 Comments

Ok, thanks, I'll read this info. But are you sure that the problem is only in file name? When we go to the page which contains a link and hover cursor over the link, we see old file address. After F5 - new address. Maybe the problem is in page, not in file?
Yes I'm sure. When you click the link, web browser saves the cache and when you click the same link again, the browser reads the cache. When you add random value as a unused GET parameter(as I showed above) the browser considers this to be a different URL without a cache - If you don't try, you won't find out :)
We tried to rename file (old name - myFile.pdf, new name - myFile1.pdf). And when we go to the page contains link and hover on the link, we see myFile.pdf. So the link text didn't update.
Do you even upload the new page?
I think you should disable index.html file cache: stackoverflow.com/questions/41631399/… This should solve the problem
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.