標籤:str validate 壓縮版 style end bsp 路徑 pts ges
優點:修改js或css時會自動產生hash版本號碼。
缺點:需要在BundleConfig中先添加對應的檔案,然後在html中再引用對應的bundle,多操作了一步。
web.config中 <compilation debug="true" targetFramework="4.5" />
1、BundleConfig
如果是偵錯模式,前端頁面會顯示真實的js、css路徑,生產環境是會顯示前面的路徑。在bundles中還可以使用萬用字元引用。
bundles.Add(new ScriptBundle("~/bundles/jquery").Include( "~/Scripts/jquery-{version}.js")); bundles.Add(new ScriptBundle("~/bundles/jqueryval").Include( "~/Scripts/jquery.validate*"));
bundles.Add(new ScriptBundle("~/bundles/bootstrap").Include( "~/Scripts/bootstrap.js", "~/Scripts/respond.js")); bundles.Add(new StyleBundle("~/Content/css").Include( "~/Content/bootstrap.css", "~/Content/site.css"));
2、前端頁面
@Styles.Render("~/Content/css") @Scripts.Render("~/bundles/modernizr")
3、Global檔案中
要在Application_Start事件中註冊Bundles。
BundleConfig.RegisterBundles(BundleTable.Bundles);
4、說明
只有在生產環境,修改js、css檔案才會產生版本雜湊值。
在生產環境,使用bundles的方式會自動引用壓縮版min檔案。
5、說明
偵錯模式
生產環境
MVC-採用Bundles方式引入css和js檔案