We (as developers) nonchalantly refreshed the page and happily continued, others didn't and we quickly realised that "Oh, they just need to refresh the page" wasn't good enough.
Solution
We needed a way to make the users refresh their browser caches, but how since we have no control over their browsers?I came up with a bit of JavaScript that will do a hard refresh of the page and use cookies to record that it has been refresh and ensure that it only happens once and doesn't go into an infinite loop.
Here is some code I came up with:
//jquery plugin for cookies <script type="text/javascript" src="/js/jquery/jquery.cookies.2.0.1.min.js"></script> <script type="text/javascript"> //give it a new name each time you need to do this var cookieName = 'refreshv1'; //check client can use cookies if ($.cookies.test()) { //get the cookie var c = $.cookies.get(cookieName); //if it doesn't exist this is their first time and they need the refresh if (c == null) { //set cookie so this happens only once $.cookies.set(cookieName, true, { expires: 7 }); //do a "hard refresh" of the page, clearing the cache location.reload(true); } } </script>Feel free to work with this code but please do not use it without testing or ensuring it is right for your situation. It is merely an idea that worked for me.
It's easier to append a query string to the stylesheet link. I believe the same applies to images and javascript files too.
ReplyDeletePete
Ha. Yeah that's true, good plan. This turned out to be a non-issue for us in the end but thought the code was still interesting
ReplyDeleteHi Colin
ReplyDeleteDoes this work the same with meta tags?
META HTTP-EQUIV="Pragma" CONTENT="no-cache"
META HTTP-EQUIV="Expires" CONTENT="-1"
@Colin - Meta Expire will only affect the current page you are on; not what was previously cached by the browser. It works well in most cases but will not work 100% onLoad.
ReplyDelete@Seffy *correction
DeleteTHANK YOU SO MUCH!!! This solves my problem.
ReplyDeleteI am happy to find this post very useful for me, as it contains lot of information.
ReplyDelete1337x
Excellent read, Positive site, where did u come up with the information on this posting? I have read a few of the articles on your website now, and I really like your style. Thanks a million and please keep up the effective work,If anyone interested similar one's have a look here thanks.
ReplyDeleteshih tzu puppies for sale near me
buy puppy online
fuhrerschein-kaufen-schweiz