Bundle vs Minification,Which one is the best

只谈情不闲聊 提交于 2020-01-14 12:12:33

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!