I am fighting about a web application script optimization. I have an ASP.NET web
ID: 646632 • Letter: I
Question
I am fighting about a web application script optimization. I have an ASP.NET web app that reference jQuery in the master page, and in every child page can reference other library or JavaScript extension.
I would like to optimize the application with YUI for .NET.
The question is, I should put all the libraries reference in the master page or to compress all the JavaScript code in a single file, or I should create a file for every page that contains only the code useful to the page?
Is there any guidance to follow?
Explanation / Answer
For common libraries, link to a CDN
The point of combining JS imports is to cut down on the number of HTTP requests required to load the page.
With that in mind, common libraries like jQuery may already be on in the user's browser cache. By using a common CDN link, your users get the speed advantage of a pre-warmed cache and you get the added benefit of not having to maintain a local copy on your server.
Any common JS library of appreciable size will usually have the ability to fetch the code from an internal or third-party (ex google) CDN. They will usually provide links to multiple versions so users can lock into a specific while the dev team maintains the freedom to continue development.
To give you an idea, here's the test runner for one of my projects. If you 'View Source' you'll see that jQuery is being served by the Google APIs CDN and qUnit is being served by the jQuery CDN.
For local stuff, it might be a good idea to compile everything into one file
It depends on the size of your codebase but there is a measurable benefit to be gained by reducing the number of web requests required to load the page. The same rule holds true for using image sprites for the UI/CSS.
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.