views:

114

answers:

3

All of my web pages use a JavaScript library, to improve the performance of my web page, I'd remove all the unnecessary functions/objects from the library for each page according to what's needed for those individual pages. I'm looking for a tool that can do the intelligent stripping automatically.

Or in the opposite direction. it will do also to have a tool to extract only the really needed functions and objects from a JavaScript library for a particular page.

Thanks for your help,

Yu

+5  A: 

This sounds like very premature optimization to me. Have you verified the mere presence of the library functions you aren't using are causing performance problems? I would be very surprised if that is truly the case.

As always, code first, only optimize after you've recognized a performance problem, profiled and isolated the cause.

Rex M
A: 

I don't know of anything out of the box, but I would recommend at least first making sure that you're gzipping the output from the webserver, stripping out the whitespace, and forcing the browser to cache the javascript permanently. That way your users will download a smaller file once and not have to download it again. Of course if something changes, you'll need to change the url. You can do this automatically if you're regularly changing the file, or manually if you only make changes infrequently.

NickAtuShip
+4  A: 

Making several versions of your javascript library for different pages will defeat caching, and subsequent pages after the first page that users visit for the first time will take longer as it requests each page's version of the library than if there was one shared javascript library already in their cache.

David