Clearing cache and cookies

bfuchs
bfuchs used Ask the Experts™
on
Hi Experts,

I find many times after doing some changes on my site that it does not work properly, and IT guys suggested that we clear cache and cookies.

Wondering how can I make it work w/o having users manually clear their cache and cookies.

In case that is not possible, can we add a button/utility that will do do the clearing for them?

Thanks
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Dr. KlahnPrincipal Software Engineer

Commented:
If you configure the browser options on each system so that browsers clear cookies when the program exits, then all the users must to do to update the site view is close the browser and restart it.  Cache is automatically cleared when a browser exits.

Firefox configuration
Note:  Firefox in particular can "hang around" for up to 30 seconds after it is closed, so users should wait a minute before restarting the browser.
Dave BaldwinFixer of Problems
Most Valuable Expert 2014

Commented:
Nothing on a web page can clear cache.  That would be a huge security risk.  And only the site that set the cookies can clear them from a web page.  The users can do it for themselves thru the browser options though it must be done separately for each browser.
leakim971Multitechnician
Top Expert 2014

Commented:
Ensure you’re charging the right price for your IT

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden using our free interactive tool and use it to determine the right price for your IT services. Start calculating Now!

Dave BaldwinFixer of Problems
Most Valuable Expert 2014

Commented:
I believe leakim971's suggestion about incognito mode will work to view the pages, it will not clear the cache and cookies, it just ignores them.
@ Dr klahn,
I am trying to accomplish something that would not require users interaction, if possible...

@Dave,
And only the site that set the cookies can clear them from a web page.  
So that it something I can work with, as we are only looking to clear those cookies that were created by using our application (I believe).

@Leakim,

you can just by opening the page in incognito mode
At the moment I am facing this issue with the user who is performing the testing, and for that it may work, however if this issue can occur in production as well, I would not be happy with that solution...

Thanks,
Ben
Hi,

What you can do for a CSS and JavaScript files to get refreshed is to check file date and time using  https://www.php.net/manual/en/function.filemtime.php

It will compare the site file vs the one that are cache in user browser if the site file is newer it will refresh
Here is how I'm using it
<?php echo '<link rel="stylesheet" type="text/css" href="ASLibrary/css/theme.css?' . filemtime('ASLibrary/css/theme.css') . '" />'; ?> 

Open in new window


Sometimes hosting company offer advance cache and this can be clear as well.
leakim971Multitechnician
Top Expert 2014

Commented:
as suggested by lenamtl, you just need to append a new number as parameter

<script src="somefile.js?version=1.2.0"></script>

if your script change, you change the version (revisuon);
<script src="somefile.js?version=1.2.1"></script>

or minor :
<script src="somefile.js?version=1.3.0"></script>

or major :
<script src="somefile.js?version=2.0.0"></script>

we don't really care about the number (revision, minor, major, that what pro do :)
The advantage with filemtime over manual versioning  is that you don't need to change the version each time you make a modification.
It is an automatic way to manage it.
I have the following in my PHP file.

		<script src="../js/MyFile.js"></script>
		<script src="../js/MyFile.js"></script>

Open in new window

What should I update to?

And that will only help for changes done on JavaScript file or to all changes on that web page (usually done thru Caspio tools)?

Thanks,
Ben
Mostly for Javascript and CSS (this can be use with image and some other element) that are cached by the browser.
Multitechnician
Top Expert 2014
Commented:
I have the following in my PHP file.

I believe your prod environment is on Caspio not on your dev box?
So you can't apply this for prod
that's why I recommend versions :

		<script src="../js/MyFile1.js?v=1.2.0"></script>
		<script src="../js/MyFile2.js?v=4.2.9"></script>

Open in new window

Thanks to ALL participants!

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial