Bundling large static Javascript libraries with ASP.NET?

Viewed 53

I have several different ASP.NET applications that all use the same version of jQuery. If I reference the jQuery library directly, my browser downloads it once and then caches it for the remaining requests.

However, if I bundle the jQuery library with every application and page that needs it, my browser essentially downloads a different copy of jQuery with each page/bundle.

It seems to me that for a large static Javascript library that is used on many pages, it would be preferable to not bundle it and just save bundling for those many, small, focused Javascript files found on each application/page.

Am I missing something? Why bundle a JavaScript file that never changes and is used in many different pages?

1 Answers

The whole point of bundling several JavaScript files together is to reduce the number of requests back to the server. Since bundling is about reducing server requests, the file size is a separate issue and that's where minification comes in.

I often take other people's designs and incorporate them into ASP.NET project templates, using both Web Forms and MVC. I almost always have to strip out the Scripts folder and comment out the bundling methods at startup. One particular problem is that the Bundling/Minification in ASP.NET can choke if there are Import statements in your CSS files. Using browser dev tools, I approach each project on a site-by-site, page-by-page basis, paying attention to payload and performance. Image sizes often cause the most issues and that is usually where I can make savings.

Related