MVC 之BundleConfig捆绑压缩技术

这个在MVC4的时候新添加的功能,目的在于合并和压缩多个js文件或者css

达到加快网站访问速度的目的.

 

格式:

 

bundles.Add(new StyleBundle("~/Content/themes/base/css").Include(
"~/Content/themes/base/jquery.ui.core.css",
"~/Content/themes/base/jquery.ui.resizable.css",
"~/Content/themes/base/jquery.ui.selectable.css",
"~/Content/themes/base/jquery.ui.accordion.css",
"~/Content/themes/base/jquery.ui.autocomplete.css",
"~/Content/themes/base/jquery.ui.button.css",
"~/Content/themes/base/jquery.ui.dialog.css",
"~/Content/themes/base/jquery.ui.slider.css",
"~/Content/themes/base/jquery.ui.tabs.css",
"~/Content/themes/base/jquery.ui.datepicker.css",
"~/Content/themes/base/jquery.ui.progressbar.css",
"~/Content/themes/base/jquery.ui.theme.css"));
}

 

在视图中可以这么写 @Styles.Render("~/Content/themes/base/css")

这样最终的网页会加载一个css ?里面的内容是jquery.ui的全部css压缩合并后的内容

 

web.config 的配置
<system.web>
<compilation debug="true" targetFramework="4.5"/>
debug="false"的时候就启用的压缩

 

在VS调试中默认是不会启用这个功能的 ?在发布网站的时候 会自动把属性debug改成false

 

点赞

发表评论

电子邮件地址不会被公开。必填项已用 * 标注