从MVC4开始,我们就发现,项目中对Global.asax进行了优化,将原来在MVC3中使用的代码移到了【App_Start】文件夹下,而Global.asax只负责初始化。其中的BundleConfig类就有个很牛X的功能:合并与压缩。想到以前做ASP.NET的时候要通过工具压缩,手动合并,很麻烦。通过BundleConfig可以大大的提高工作效率和项目性能。
一、基本的使用
1.1、Global.asax文件的初始化
protected void Application_Start() { RouteConfig.RegisterRoutes(RouteTable.Routes); }
1.2、BundleConfig 绑定压缩文件
public class BundleConfig { // 有关 Bundling 的详细信息,请访问 http://go.microsoft.com/fwlink/?LinkId=254725 public static void RegisterBundles(BundleCollection bundles) { bundles.Add(new ScriptBundle("~/bundles/jquery").Include( "~/Content/Scripts/jquery-{version}.js" )); bundles.Add(new ScriptBundle("~/Content/Scripts/toojs").Include( "~/Content/Scripts/jquery.cookie.js", "~/Content/Scripts/footer.js" ));