0

I searched everywhere and I can only find solutions that I do not understand (I am not really skilled in web development).

If I understand correctly, the best method is the versionning of javascript and css calls. But I don't understand how I am supposed to implement this in my website or server.

Would someone have an idea or a link for a beginner like me? (the easiest method is the best for me I suppose)

Right now my users have problems with the website, but all problems vanish when the cache is cleared. It's a big problem.

Thanks anyway guys. Have a nice day.

David Gourde
  • 3,209
  • 19
  • 54
  • Maybe this helps http://stackoverflow.com/questions/49547/making-sure-a-web-page-is-not-cached-across-all-browsers – Miguel Mota Jun 26 '14 at 20:54

2 Answers2

1

You can use the PHP header:

header('Cache-Control: no-cache, no-store, must-revalidate');
header('Pragma: no-cache'); 
header('Expires: 0');

You can place it where the headers are being called

Or use the meta tag instead:

HTML:

<meta http-equiv="Cache-Control" content="no-cache, no-store, must-revalidate" />
<meta http-equiv="Pragma" content="no-cache" />
<meta http-equiv="Expires" content="0" />

This way your browser won't store cache.

However, cacheing headers are unreliable in meta elements; for one, any web proxies between the site and the user will completely ignore them. You should always use a real HTTP header for headers such as Cache-Control and Pragma.

imbondbaby
  • 6,063
  • 3
  • 17
  • 51
  • Thank you for yout answer. I think it's a good idea, but I still want to use the cache when the website is not updated, so I chose the Richard's answer that let me do that. – David Gourde Jun 27 '14 at 14:40
1

Simply add a new parameter to the end of the file every time you update it, eg

<script src="http://www.example.com/javascript.js?reload=1">

and

<script src="http://www.example.com/javascript.js?reload=2">

will both be treated as different files, despite actually being exactly the same..

If you need it never to cache, then change the parameter dynamically every page load using a script (adding a timestamp is the usual approach as that will never get accidental repeats).

RichardB
  • 2,525
  • 1
  • 9
  • 14
  • Thanks, I will do exactly that, using a variable named with the version of my site to control when to cache and when not to cache. Hoping everything will work well. Thank you again. – David Gourde Jun 27 '14 at 14:39