How to load Javascript Files in client system once and reuse them?


I have a large scale application which uses javascript for many reasons. these javascript files included in some JS files and JS files imported to Masterpage files.

this JS files contents (javascript functions) will add to page when page display to user, so a Bunch of waste Javascript functions will include in pages.

I'm lookingfor a way which these JS files downloads to users computer (any where, e.g: temporary internet files or some where else) and the page use that functions which downloaded with page.

I also want to download 1 time ( per user login or per Open Session ) to users computer.

So How to download JS file to Users PC and Use them in Pages


The browser does exactly that automatically for you, whenever a browser downloads a file(in your case a js) he stores it in a temp directory for later usage thus optimizting overhead, the same applies for pictures.

You can farther optimize it by using some sort of CDN, for example Google have a cdn for many common JavaScript libraries.

So, once again - after the users browser downloaded the script, he will try to re-use it, based on name.

so, if your scripts resides on the same place, you get this functionality for free!

By : MindFold

Check out ASP.NET Performance - Part 2 - YSlow by Karl Seguin on how to write a HttpHandler to add caching headers for static files.

I would advise you to read the other 4 posts as well on caching strategies for ASP.Net. This will give you a better understanding on what's going on when serving pages from a webserver to a browser.

Client side caching is, well stating the obvious, dependent on the clients behavior. Have a look at Some of the recommendations are

  • Set Expires instead of Cache-Control (as it is more widely supported by clients).
  • Avoid setting the Vary header (IE).
  • When fetching files over https use Cache control: public (Some versions of FF)

There are also some suggestions about how to allow web-proxies to cache (and funnilly enough the recommendation: Don't include a query string in the URL for static resources., is broken by their own CDN)

By : Mads Ravn

This video can help you solving your question :)
By: admin