Smart Javascript Usage

To optimize page sizes, it would be great if:

a) Javascript (and CSS) files can be generated on a custom basis based only on the features being used by the site.

b) Load the javascript files as needed.

i.e. if form_scripts.js or exceptions.js is not needed until the product page, then do not load it on the home page.