How to force browsers to fetch new files instead of cache (images, CSS, JS, etc)
Working around this is an easy fix: add GET variables to your file paths.
For example, if you were linking your file:
Simply add a random string as a GET variable:
As the browsers will now see this as a new URL, it will attempt to get the file again, which will return in the new file being fetched instead of cache.
If you want the browser to always get the new file, you can use php to attach a random string with the path to return a new file path every time, like so:
http://aliishaq.net/js/example.js?v=<?php echo rand(); ?>
But a better way would be to assign version to your files. For example, your initial file can be
and if you make any change to it, you can just change it to something like
I hope this is helpful and resolves the kind of problems I faced.