2

My problem is the following: I've built a website for an event last year (edition 2014). Now I've created a website for the same event, but for this year (2015). However, whenever I visit the website, it opens the 2014 version, even though I've put the other version up... Pressing F5 refreshes the page en shows the 2015 site.

So I believe the problem is this web page is a cached version and that that's the reason this happens. Here's my question: Is there any way this can be fixed? (Thinking of a JavaScript script to clear every visitor's cache of this website...)

P.S.: The site uses HTML5, CSS3, JavaScript in 2015. HTML4 and CSS2-3 (idk anymore) in 2014 version.

pnuts
  • 58,317
  • 11
  • 87
  • 139
parthannun
  • 29
  • 1
  • 2
  • 3
    You could append something like `?v=2015` on the end of your `.css` and `.js` file calls so that the browser re-loads them and doesn't cache the old versions. – Albzi Oct 13 '15 at 16:03
  • 1
    Unfortunately, this question is too broad for SO, there are too many ways to do this. @Albzi What about the main page? – Ruan Mendes Oct 13 '15 at 16:04
  • Never mind. I understood after a while. I think my brain broke for a second. @JuanMendes – Albzi Oct 13 '15 at 16:05

5 Answers5

2

Do this for css and javascript

<link rel="stylesheet" type="text/css" href="yourlink/filename.css?v=2"/>   

<script src="yourlink/filename.js?v=2"></script>
Alex
  • 8,461
  • 6
  • 37
  • 49
0

Here's a pretty good cache control tutorial: http://www.mobify.com/blog/beginners-guide-to-http-cache-headers/

However if you didn't apply these tricks in your 2014 edition I guess there's no good ways to expire the already cached 2014 edition from users' browsers. Probably the best you can do now is to put 2015 edition at a different URL.

charlee
  • 1,309
  • 1
  • 11
  • 22
0

You can't clear the 'traditional' browser cache via client- or server-side code, at least not in a cross-browser compatible way. You could tell the browser not to cache your page by sending the appropriate headers or using these meta tags:

<meta http-equiv='cache-control' content='no-cache'>
<meta http-equiv='expires' content='0'>
<meta http-equiv='pragma' content='no-cache'>

Alternative you could version all your resources, e.g. img-2015.png versus img-2014.png

Alex
  • 21,273
  • 10
  • 61
  • 73
0

If the browser doesn't calculate an expiration date in the past maybe it will try an http request with the HEAD method. This method should return the same metadata as a GET would do. So you may be able to trigger a refresh GET request by setting correct http cache headers on the HEAD request. This should force the browser to recognize its cached version as stale and retrieve the data with a GET.

user392486
  • 195
  • 4
-3

One option is, you could give the file a different location on the server and do an server-side redirect.

Ally Rippley
  • 525
  • 2
  • 6