Forcing a Hard Refresh of cached website - in code?

Hi

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 asp.net) if the version ID's are different
but i'm not sure if its cross browser compliant etc

advice appreciated
websssAsked:
Who is Participating?
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
0

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
websssAuthor Commented:
Hi Edwin

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

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

Best Regards
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

websssAuthor Commented:
Really?
How would I stop the js file from caching using 2nd method ?
0
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.
0
websssAuthor Commented:
great answer!
0
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
HTML

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.