How can I change cachable content so that the user will immediately get the refreshed version?
I’ll give an example: I have a .css file that is cachable for 2 weeks, so even if I change it, users will still get the old version, unless the press F5.
There are a few solutions, that I know of, but none are perfect:
- Changing the filename (from main.css to main2.css).
- Adding a unique URL parameter (like main.css?v=1).
I think that this could somehow be solved using apache eTags and I tried once with that but no luck.
I think that the best bet is to use the second option: add a parameter to the URL. So instead of writing
css/main.css, just writecss/main.css?v=1and then increment thev(as in version) parameter. I see it used all the time.Sometimes a timestamp is added instead of the version, but be careful not to change this timestamp with every access to the page, as that would result in users never using their cache.