Disable .pdf caching
-
My site has some pdf files that are updated frequently due to rescheduling, etc., and I want the users to always get the updated version, not a cached version. I only want this for pdf files. Is there a setting to do this? If not, any suggestions as to what else I might use?
-
Hello @terry777
Thank you for reaching out and I am happy to help!
This requres just a small tweak in the settings. I am assuming that when you say you update the version of the PDF files, you are using the same name of the files and just re-upload the updated version?Please let me know if this is the case.
If I am correct, the problem is with the Browser Cache and the cache-control / expires header. Since you havnet share the website URL, I cannot confirm this, however, if you go to Performance>Browser Cache, and scroll down to media&Other files section, you will see that the default Expires header lifetime: is 31536000 or one year.
This is a standared for static files and this means those files remain cached in the browsers of the users that visited the website, and this is because next time they visit, the browser will recognize them, and fetch the exisitng version so there is no need to download those files again!This is easily solved with Cache busting option in the W3 Total Cache Browser Cache settings which you can find in the same sub-box “Media&Other files”. This option is called ” Prevent caching of objects after settings change”
What this option does is when enabled it adds the query string to the static files for example https://yourwebsite.com/wp-content/uploads/some-pdf-file.pdf?xNNNNNThis random query string is used for versioning of the files so that next time you update any file and update the query string, the browser will see that query string, it will not recognize it and iwll fetch the updated file from the server
Make sure to enable this option, save all settings and purge the cache. Next time you update the file, go to Performance>Browser Cache, click the “Update Media query string” button at the top of the page as shown in the screenshot below, save all settings and purge the cache
Please let me know if you need any clarfication and if this helps!
Thank you!
Thanks for your response. I kind of get how it works, and did get it to work, once, but it needs to be more automatic somehow.
If I’m reading this correctly, every time I edit the pdf, and replace it in the media library, I have to manually “go to Performance>Browser Cache, click the “Update Media query string” button at the top of the page as shown in the screenshot below, save all settings and purge the cache”? Or, is that a one-time process?
The problem is, on some sites another user may edit a regular page, such as a meeting schedule change. I don’t want to have to manually clear the cache every time something is updated, and I certainly don’t want another logged-in user who edits a page to do it. Isn’t there a way to have it recognize there is a change automatically? Is there a way to have a list of pages that are regularly updated and should not be cached?
What is the simplest way to make user non-logged-in users see the most recent version as soon as it’s published?
Thanks.
Hello @terry777
Sorry for the late reply!
If I’m reading this correctly, every time I edit the pdf, and replace it in the media library, I have to manually “go to Performance>Browser Cache, click the “Update Media query string” button at the top of the page as shown in the screenshot below, save all settings and purge the cache”? Or, is that a one-time process?
Yes, and the reason you need to always update the media query string if you are changing the file is because of the file-name as I explained before.
As for the other question, you can purge the specific page when edited, so you do not need to purge all cache.
There is no specific way to automate this and the reason is as I mentioned the browser Caching of the files.
Alternatively, you can disable the expires headers and cache-control headers for media&other files in the Browser Cache settings.
Do you want me to check for some custom rules to only avoid caching the PDF files?Thanks!
You must be logged in to reply to this topic.