I am wondering how may times the bundling and minification runs on the server?
Is it once per HTML request? Once per browser session? Once every time the app gets deployed?
Bundling and minification are two distinct performance optimizations you can apply in a web app. Used together, bundling and minification improve performance by reducing the number of server requests and reducing the size of the requested static assets.
Bundling and Minification are two performance improvement techniques that improves the request load time of the application. Most of the current major browsers limit the number of simultaneous connections per hostname to six. It means that at a time, all the additional requests will be queued by the browser.
Bundling and minification is enabled or disabled by setting the value of the debug attribute in the compilation Element in the Web. config file. In the following XML, debug is set to true so bundling and minification is disabled. To enable bundling and minification, set the debug value to "false".
Both bundling and minification are the two separate techniques to reduce the load time. The bundling reduces the number of requests to the Server, while the minification reduces the size of the requested assets.
Bundles are created when the application is deployed or restarted, when the Application_Start
method is called in Global.asax.cs
. Inside Application_Start
, BundleConfig.RegisterBundles
is invoked, which is actually where the magic happens.
public class MvcApplication : System.Web.HttpApplication
{
// this method is called on application start
protected void Application_Start()
{
AreaRegistration.RegisterAllAreas(); // registers areas
FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters); // registers filters
RouteConfig.RegisterRoutes(RouteTable.Routes); // registers routes
BundleConfig.RegisterBundles(BundleTable.Bundles); // this generates the bundles
}
}
And in your BundleConfig.cs
file, the RegisterBundles
method is the method that is called to create said bundles.
public class BundleConfig
{
public static void RegisterBundles(BundleCollection bundles)
{
// this is actually what's creating the bundles
bundles.Add(new ScriptBundle("~/bundles/jquery").Include(
"~/Scripts/jquery-{version}.js"));
// etc...
}
}
They are then cached in memory, can be accessed at /bundles/bundlename?v=versionId
, and served for each HTTP request, but the actual process of bundling and minification only happens once.
bundling and minification registered with Application_Start runs once and result is cached on server. Cached version provides for other request. Aplication_Start fires when first resource requested.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With