首页 > 代码库 > MVC 压缩静态资源

MVC 压缩静态资源

一、导入包 install-package Microsoft.AspNet.Web.Optimization 

二、

public class BundleConfig
{
  	public static void RegisterBundles(BundleCollection bundles)
        {
    //css公共部分
            bundles.Add(new StyleBundle("~/bundles/csspublic").Include(
                "~/Content/css/style.css",
                "~/Content/css/main.css",
                "~/Content/css/main_01.css"
                ));
            //js 公共部分
            bundles.Add(new ScriptBundle("~/bundles/jspublic").Include(
                /* "~/Content/js/lanrenzhijia.js",
                 "~/Content/js/tupian.js",
                 "~/Content/js/jquery.lavalamp.min.js"*/
                ));
}
}

 

三、在Global.asax.cs 中加入配置

protected void Application_Start()
        { 
            BundleConfig.RegisterBundles(BundleTable.Bundles);
         
        }

  

 

MVC 压缩静态资源