I'm looking at improving the performance of page load and render time of a rather complex ASP.NET site.
Due to the use of a lot of ASP.NET controls that themselves include javascript files (by simply using the script-tag) certain pages load the same javascript up to 10 times. Additionally, some javascript must be loaded early in the page, while others is better included at the end. Some I would like to dynamically load after the onload event instead of explicitly include in the page.
The way I'm thinking about is to let all the different controls register their need of a particular javascript file in a central place that in turn controls the generation of script-tags (thus avoiding duplicates) and where they are inserted into the generated output. This would also make it easy to dynamically switch between minified and full javascript files (e.g. appending debug=true to the query string would make files load by filename.debug.js instead of filename.compressed.js).
Using this solution it would also be possible for it to basically generate a javascript array of filenames that are used by a custom onload javascript function to dynamically load the scripts.
What is the best way to accomplish this? Use or extend something like ScriptManager, make a custom Control, override the Page object?