The advantage of including js on web page is that I need not to worry about cached js file. If I change it on the server, the same will be reflected on client side. But it increases the size and complexity of webpage. It also affects average response time.

But if I make a separate js, so it could be saved at client side on first request, client needs to remove cached js when I do some changes in js at server side.

Is there any way (some HTML tag or attribute) to indicate to the browser that js file has been changed at server side. So it downloads the new copy. Or something like versioning.

  • HTML5 provides a good way to handle it using manifest Feb 7, 2014 at 14:50

3 Answers 3


Use a made up query string attached to the end of the file name. Browsers think the file is new and download it. The query string does not affect the file.

So <script type="text/javascript" src="your.js?123"></script>

  • This is probably the easiest solution, although I keep hearing reports that certain browsers and proxies don't cache files with query strings in them. Jun 15, 2011 at 11:53
  • I am satisfied with @Jason Gennaro and @Bob Baddeley answers. I would like to add one more point which came in my mind after a doubt. If a js is being referred from mass number of webpages then changes on every page would not be possible. In such a case, Create a separate tile/templet/master page which have all common resources and settings. So the changes at one place would be applicable to all places. Jun 15, 2011 at 15:46

This is what version numbers are good for. If you include your file with a version number in the file name (like jquery-1-5-1.min.js), then later when a new version of the file is deployed you update with the new version number (like jquery-1-6-0.min.js), then you don't have to worry about the caching.


    var ts = new Date().valueOf();//creating timestamp
    var newScript = document.createElement('script'); //creating script tag
    newScript.type = 'text/javascript';
    newScript.src = 'jquery-1.3.2.min.js?'+ts;// reference to jS with timestamp as a query string
    document.body.appendChild(newScript);//appending it to dom

Add this script tag to body. Every time JS will be updated a fresh file.

  • But this means the file will be downloaded on every single page load! That's incredibly inefficient. Jun 15, 2011 at 11:52
  • @DisgruntledGoat is correct. There would be no sense for caching the cache as i mentioned in 2nd paragraph of my question. Jun 15, 2011 at 15:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.