Forcing a Hard Refresh of cached website - in code?


Is there anyway (in code) to force a complete refresh of a website?

in a browser, I usually use ctrl F5
However, I need to the code to handle it on demand

Is this possible?

the idea is to write a cookie with the Version ID, and if the Version on the login page is different to that in the cookie then it must get a fresh copy and not use the cache

I know you can use Meta tags for No-cache etc, but would welcome some more insight

a possibility is to append the HTML with the no-cache meta tag (using if the version ID's are different
but i'm not sure if its cross browser compliant etc

advice appreciated
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Edwin HofferTechnical ExpertCommented:
Hello websss,

You can force the page not to cache by adding cache control meta tags:

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

Open in new window

You can also prevent caching of your stylesheet by adding a version get parameter:

<link rel="stylesheet" href="style.css?v=1" type="text/css" />

Open in new window

Hope that helps

Best Regards

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
websssCEOAuthor Commented:
Hi Edwin

Very interesting point about the ?v=1 on the CSS file
Does this also work on the Javascript files too?
Edwin HofferTechnical ExpertCommented:
Hello Websss,

You don't need to add any version in JS files.

Best Regards
Determine the Perfect Price for Your IT Services

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

websssCEOAuthor Commented:
How would I stop the js file from caching using 2nd method ?
Edwin HofferTechnical ExpertCommented:
Ohh, sorry but if you want to prevent js file from caching then you have to use:

<script src="js.js?v=1"></script>

Open in new window

this will prevent from caching.
websssCEOAuthor Commented:
great answer!
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.