views:

74

answers:

2

Hi

I have some tabs that are ajax powered. So everytime a tab is clicked all data is loaded including javascripts. So if they click on say Tab A then click on Tab B and finally Tab A. All Tab A scripts will be loaded twice.

Now I am wondering how does the caching work. On the second time they click on Tab A how much faster will these scripts download? Or will it be as slow as the first time?

Thanks

+2  A: 

Assuming a fairly regular load, the script will load the first time, and be pulled from the cache from then on.

Unless you're doing something tricky.

Just like you can load a huge script on the first page request of a more traditional site, and include that script of subsequent pages, but after the first page load, the browser will (typically) just pull it from cache.

Use firebug and observe the behavior.

timdev
I am guessing the stuff in the actual script wont' go faster though right?
chobo2
@chobo2: If the browser is re-parsing JavaScript, even if that JavaScript resides in a file that is returned from cache, the browser will still have to JIT the JavaScript in that file. It is highly unlikely any browser would attempt to hold onto JITed script after the page content containing that script has been discarded. So although cached external JavaScript files will speed up loading, the JavaScript will still have to be JITed each time. But honestly, the load time is probably much, much longer than the JITing time regardless.
Grant Wagner
A: 

If you are loading the same URL, the browser will use the cached version. If you want to circumvent caching, add "?" followed by a random string to the url every time u call it.

Amarghosh