views:

105

answers:

2

This is a twin question to the following:

http://stackoverflow.com/questions/1257225/javascript-stripper-remove-functions-objects-that-are-not-used-in-a-web-page

To maximize my chance of getting my problem solved, I'm asking the question in opposite manner:

All of my web pages use a JavaScript library, to improve the performance of my web pages, I'd only include only the needed functions/objects from the library for each page. I'm looking for a tool that can do the intelligent extraction automatically.

Thanks for your help,

Yu

+2  A: 

Are you sure this is a real problem?

The reason I ask is because it should not be a problem to include the same, full JavaScript library on every page. In fact, serving different versions of the library to each page will actually slow down your site.

The reason is that JavaScript is cached by the browser. If each page requests the same library, they will not have to actually download the library from your site after the first time.

The key is to make sure your library is sent with an HTTP Expires header that tells the browser to cache the response.

Nate
A: 

You are doing it wrong. Separate versions of a javascript library for each page is a bad idea since the library won't be cached but fetched separatly for each page. You're better off minifying, concatinating and GZIP your scripts and serve the exact same script file for all pages.

However, if you need to know what lines are actually run, you can probably find out using JSCoverage.

svinto