A really great blog post about how to do javascript includes using "asynchronous javascript" XMLHTTP requests to server-side PHP scripts.
The article shows how to do 'include_once' and 'on-demand' loading of javascript code, which can be executed by the browser to modify the current document, including by use of HTTP GET request results assigned to the DOM.