问题
I would like to know about which one of the following way is better.
Bundle the css files and then use :
bundles.Add(new StyleBundle("~/BootStrap/css").Include(
"~/BootStrap/css/bootstrap.css",
"~/BootStrap/css/bootstrap-responsive.css"));
OR
Use *.min file directly is as below :
<link href="~/BootStrap/css/bootstrap.min.css" rel="stylesheet" />
<link href="~/BootStrap/css/bootstrap-responsive.min.css" rel="stylesheet" />
I would expect the explanation for performance wise and also as best practices.
回答1:
Bundling is better because it not only minifies the included files but it packages them together in one resource which translates to one request to the server instead of multiple requests, one for each file.
In terms of best practice, using Bundling is part of the MVC convention so I would consider that approach to be best practice.
回答2:
I think it is difficult to say that which one is better. Both have there own pros and cons.
Check this:-
Bundling
Bundling is a new feature in ASP.NET 4.5 that makes it easy to combine or bundle multiple files into a single file. You can create CSS, JavaScript and other bundles. Fewer files means fewer HTTP requests and that can improve first page load performance.
Minification
Minification performs a variety of different code optimizations to scripts or css, such as removing unnecessary white space and comments and shortening variable names to one character.
回答3:
Use bundling with caution.
While it does decrease the number of http-requests, it makes browser cache (and proxy cache, and CDN cache and whatever cache you use) less usable.
Say, you have scriptA.js
and scriptB.js
. Some pages use A
, some pages use B
, some pages use both A
and B
With bundler its three different scripts. Without bundling it's two.
来源:https://stackoverflow.com/questions/18815823/bundle-vs-minification-which-one-is-the-best