Clearing the Cache

I have a very simple HTML website. Users of the website keep having problems accessing changes after I have made any to the coding, because their Windows 10 Cache needs clearing. It is not a problem for me, of course, because I know I need to clear the Cache each time. But third parties do not, especially if I have added links to new PDF files.

This is a regular requirement as things develop, but Users whose system has cached the old code are not made aware that things have changed since they last logged on.

Is there any way that I can force a user to clear the Windows Cache, so that they do not experience the problem ? Alternatively, is there a way to stop users automatically caching the website ? Obviously I could tell them what to do on the front page of the website, but that would mean instructions for all the different web browsers.

Is there a simple instruction in HTML which forces a user to ignore any Cache they have, and to re-load from scratch every time they access the website ?

I am not a coding expert and therefore this question may sound rather naive, but it is giving me a headache !

Thanks for any tips.

You can set “expires headers” in your .htaccess file:
https://www.seeme-media.com/add-expires-headers-to-your-htaccess-file/

3 Likes

Thanks for that. If it works, it will be a huge help.

Forgive my ignorance, but as my code is basically a series of HTML menus, each linking to HTML menus lower in the hierarchy, which then each again link to PDF files, am I correct that I would simply create a new .htaccess file containing ONLY the following code ?

ExpiresByType text/html “access plus 0 seconds”
ExpiresByType text/pdf “access plus 0 seconds”

That would presumably stop any HTML menus and any PDF files loading from the Cache, I hope ! If I understand your www.seme-media.com link correctly, the .htaccess file would contain nothing else, just those two lines ? There would be no introductory instruction about “access” ?

I have used .htaccess for password security successfully in the past, but I am not using it for password protection in this case - too many objections from users and not really necessary ! So I have no .htaccess file in use on this website at present. This would be a completely new one.

Your help on this is most appreciated.

Oh dear, I tried it and I regret it does not work. I first put the .htaccess file in the root directory and tried it - no luck. So I added it to one of the sub-directories and sadly it also made no difference - kept fetching the pdf files from the Cache.

That’s an almost “yes”, kind of. But I’ll explain below.

That’s right.

Yes, a new one in the root of your website, the htdocs folder.

You have to use the correct mime types. For HTML the correct mime type is the one you used - text/html.
But for PDF files the correct mime type is application/pdf.
Here’s a good list: Mime types for web developers.

Bear in mind that not caching your static files will make your website slower and use more hosting resources. It’s OK to do that while you are building your site but you should let those files be cached when you finish building it and the page views start to go up.

3 Likes

One thing to note is that the Expires header only tells browser how long they should store an entry in their cache. Once an item is cached, the browser will keep using that cached version until it’s expired or cleared. If you clear your cache and then try again, the item should no longer be fetched from cache afterwards.

Another thing to note is that if you disable caching for text/html content, then any other content is still cached. This includes images, CSS and Javascript files being referred to from the page. If you don’t want to cache those either, you’ll have to set the expiration header for those content types too.

4 Likes

My thanks to everyone. All is now working satisfactorily (as far as I can tell !) I have tried it several times having changed the odd file or two. But I could only get it to work by adding the .htaccess file to every directory in the hierarchy; just putting it in the root directory only did not seem to work.

I will have to wait now to see how my users react !

Thanks again.

1 Like

If it works for you, then all is good. But .htaccess rules affect the folder the file is in, in addition to any subfolders of that folder.

2 Likes

This topic was automatically closed 15 days after the last reply. New replies are no longer allowed.