I'm using ASP.net MVC 4. Like the question states, if I put a bunch of JS files (or CSS, for that matter) into a bundle, will it automatically be minified? For example, should my bundle read:
bundles.Add(new ScriptBundle("~/bundles/exampleBundle").Include( "~/Scripts/jquery-masked.js" "~/Scripts/jquery.idletimer.js" ));
Or should it instead include the minified files initially:
bundles.Add(new ScriptBundle("~/bundles/exampleBundle").Include( "~/Scripts/jquery-masked.min.js" "~/Scripts/jquery.idletimer.min.js" ));
??
Edit: Now I am wondering if bundling the .min files instead adds any optimization. Will it increase performance including the .min files in the bundle instead of the basic files? (Maybe the "minifier function" takes some time?)
Busting Browser's Cache by Bundling As we upload the changes in the static resources such as CSS and JS files on the live server, the resources changes but it does not update on the Browser, because the Browser's cache resources are based on URLs automatically.
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 techniques you can use in ASP.NET to improve page load performance for your web application. Bundling combines multiple files into a single file. Minification performs a variety of different code optimizations to scripts and CSS, which results in smaller payloads.
Creating a Bundle in MVCBundling can create separate requests for CSS and JavaScript files. For example, if an application uses both the bootstrap and site CSS for UI design, we can create a common bundle for them. After Bundling, we need to register this bundle in the Application.
You don't have to include minified files, that's automatically done by bundle engine. In fact, I remember including minified files caused problems (maybe this is fixed on latest mvc version)
You may think this is not working since optimizations (bundling and minifying) are only performed when debug=false
on web.config.
<system.web> <compilation debug="false" /> </system.web>
There is a way to force optimizations even when debug = true
using BundleTable.EnableOptimizations
. Here you have an example
public static void RegisterBundles(BundleCollection bundles) { bundles.Add(new ScriptBundle("~/bundles/jquery").Include( "~/Scripts/jquery-{version}.js")); BundleTable.EnableOptimizations = true; }
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