force download of javascript file for new deployments


I use a lot of javascript for client-side scripting, putting it into .js file and then adding script tags as follows:

<script src=”js/myclient-side.js”></script>

In all modern browsers the javascript files and the style sheets are cached to improve performance. The page load time is hugely minimized due to caching but it has a pitfall (for programmers), when you make a new deployment on the server with huge changes to a javascript file, the file is not downloaded on the client side as it is used from the local cache. There are many workarounds to this pitfall, the simplest one that i feel is as follows:

<script src=”js/myclient-side.js?v=1“></script>

by just adding “?v=1” the browser will download the javascript file and replace it in the cache, for the next new deployment you can increase the number like v=2, v=3 … etc.

Advertisements

About Dominic

J for JAVA more about me : http://about.me/dominicdsouza
This entry was posted in Thechy Stuff. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s