public static void RegisterBundles(BundleCollection bundles) { Assets.EnableOptimizations = !HttpContext.Current.IsDebuggingEnabled; var jsBundle = new JsBundle("~/bundles/js"); //jsBundle.Include("~/Scripts", "jquery-*"); //jsBundle.Include("~/Scripts", "jquery-ui*"); //jsBundle.Include("~/Scripts", "jquery.unobtrusive*"); //jsBundle.Include("~/Scripts", "jquery.validate*"); jsBundle.Include("~/Scripts/AjaxLogin.js"); bundles.Add(jsBundle); var mobileJsBundle = new JsBundle("~/bundles/mobileJs"); mobileJsBundle.Include("~/Scripts", "jquery.mobile*"); bundles.Add(mobileJsBundle); var cssBundle = new CssBundle("~/Content/css"); cssBundle.Include("~/Content/site.css"); bundles.Add(cssBundle); var mobileCssBundle = new CssBundle("~/Content/mobileCss"); mobileCssBundle.Include("~/Content", "jquery.mobile*"); bundles.Add(mobileCssBundle); var themePath = "~/Content/themes/base/"; var themeBundle = new CssBundle(themePath + "css"); themeBundle.Include(themePath + "jquery.ui.core.css"); themeBundle.Include(themePath + "jquery.ui.resizable.css"); themeBundle.Include(themePath + "jquery.ui.selectable.css"); themeBundle.Include(themePath + "jquery.ui.accordion.css"); themeBundle.Include(themePath + "jquery.ui.autocomplete.css"); themeBundle.Include(themePath + "jquery.ui.button.css"); themeBundle.Include(themePath + "jquery.ui.dialog.css"); themeBundle.Include(themePath + "jquery.ui.slider.css"); themeBundle.Include(themePath + "jquery.ui.tabs.css"); themeBundle.Include(themePath + "jquery.ui.datepicker.css"); themeBundle.Include(themePath + "jquery.ui.progressbar.css"); themeBundle.Include(themePath + "jquery.ui.theme.css"); bundles.Add(themeBundle); }
public static void RegisterBundles(BundleCollection bundles) { Assets.EnableOptimizations = !HttpContext.Current.IsDebuggingEnabled; var jsBundle = new JsBundle("~/bundles/js"); jsBundle.Include("~/Scripts", "jquery-*"); jsBundle.Include("~/Scripts", "jquery-ui*"); jsBundle.Include("~/Scripts", "jquery.unobtrusive*"); jsBundle.Include("~/Scripts", "jquery.validate*"); jsBundle.Include("~/Scripts/AjaxLogin.js"); bundles.Add(jsBundle); var mobileJsBundle = new JsBundle("~/bundles/mobileJs"); mobileJsBundle.Include("~/Scripts", "jquery.mobile*"); bundles.Add(mobileJsBundle); var cssBundle = new CssBundle("~/Content/css"); cssBundle.Include("~/Content/site.css"); bundles.Add(cssBundle); var mobileCssBundle = new CssBundle("~/Content/mobileCss"); mobileCssBundle.Include("~/Content", "jquery.mobile*"); bundles.Add(mobileCssBundle); var themePath = "~/Content/themes/base/"; var themeBundle = new CssBundle(themePath + "css"); themeBundle.Include(themePath + "jquery.ui.core.css"); themeBundle.Include(themePath + "jquery.ui.resizable.css"); themeBundle.Include(themePath + "jquery.ui.selectable.css"); themeBundle.Include(themePath + "jquery.ui.accordion.css"); themeBundle.Include(themePath + "jquery.ui.autocomplete.css"); themeBundle.Include(themePath + "jquery.ui.button.css"); themeBundle.Include(themePath + "jquery.ui.dialog.css"); themeBundle.Include(themePath + "jquery.ui.slider.css"); themeBundle.Include(themePath + "jquery.ui.tabs.css"); themeBundle.Include(themePath + "jquery.ui.datepicker.css"); themeBundle.Include(themePath + "jquery.ui.progressbar.css"); themeBundle.Include(themePath + "jquery.ui.theme.css"); bundles.Add(themeBundle); }
private void RenderScriptReferences() { // Get scripts that are added by the framework var frameworkScriptPaths = GetFrameworkScripts(); // Construct smart list var smartList = new List <string>(); // Hard-code WebForms.js - it will be rendered here, and not in Page (like by default) smartList.Add(GetUrl(new ScriptReference(this.Page.ClientScript.GetWebResourceUrl(typeof(System.Web.UI.Page), "WebForms.js")))); // Add scripts needed by the framework smartList.AddRange(frameworkScriptPaths); // Add scripts previously added to this control smartList.AddRange(this.Scripts.Select(s => GetUrl(s))); // Add scripts from the smart loader smartList.AddRange(SmartLoader.GetScriptsToLoad()); // Clear previous scripts (they are now part of smartList) Scripts.Clear(); // Initialize bundling var allowJsBundling = PortalContext.Current.BundleOptions.AllowJsBundling; var bundle = allowJsBundling ? new JsBundle() : null; // Go through all scripts foreach (var spath in smartList) { var lower = spath.ToLower(); if (lower.EndsWith(".css")) { UITools.AddStyleSheetToHeader(UITools.GetHeader(), spath); } else { var isPostponed = PortalBundleOptions.JsIsBlacklisted(spath); var isFrameworkScript = frameworkScriptPaths.Contains(spath); if (isPostponed) { _postponedList.Add(spath); } if (allowJsBundling && !isPostponed) { bundle.AddPath(spath); } if (!isPostponed && !isFrameworkScript) { Scripts.Add(new ScriptReference(spath)); } } } // Go through postponed scripts foreach (var spath in _postponedList) { Scripts.Add(new ScriptReference(spath)); } // NOTE: At this point, script order is the following: // 1) scripts added by the framework // 2) scripts added directly to this control // 3) scripts from SmartLoader (that are not blacklisted from bundling) // 4) scripts from SmartLoader (that are blacklisted from bundling) // Finalize bundling if (allowJsBundling) { // If bundling is allowed, close the bundle and process it bundle.Close(); BundleHandler.AddBundleIfNotThere(bundle); ThreadPool.QueueUserWorkItem(x => BundleHandler.AddBundleToCache(bundle)); if (BundleHandler.IsBundleInCache(bundle)) { // If the bundle is complete, use its path to replace the path of all the scripts that are not postponed _bundle = bundle; } } }
private void RenderScriptReferences() { var smartList = SmartLoader.GetScriptsToLoad(); var allowJsBundling = PortalContext.Current.BundleOptions.AllowJsBundling; JsBundle bundle = null; List <string> postponedList = null; if (allowJsBundling) { bundle = new JsBundle(); postponedList = new List <string>(); } foreach (var spath in smartList) { var lower = spath.ToLower(); if (lower.EndsWith(".css")) { UITools.AddStyleSheetToHeader(UITools.GetHeader(), spath); } else { if (allowJsBundling) { // If bundling is allowed, add the path to the bundle - if it is not blacklisted if (PortalBundleOptions.JsIsBlacklisted(spath)) { postponedList.Add(spath); } else { bundle.AddPath(spath); } } else { // If bundling is disabled, fall back to the old behaviour var sref = new ScriptReference(spath); Scripts.Add(sref); } } } if (allowJsBundling) { // If bundling is allowed, closing the bundle and adding it as a single script reference bundle.Close(); BundleHandler.AddBundleIfNotThere(bundle); ThreadPool.QueueUserWorkItem(x => BundleHandler.AddBundleToCache(bundle)); if (BundleHandler.IsBundleInCache(bundle)) { // If the bundle is complete, add it as a single script reference var sref = new ScriptReference("/sn-bundles/" + bundle.FakeFilename); Scripts.Add(sref); } else { // The bundle will be complete in a few seconds; disallow caching the page until then this.Page.Response.Cache.SetCacheability(HttpCacheability.NoCache); // Fallback to adding every script again as separate script references foreach (var path in bundle.Paths) { var sref = new ScriptReference(path); Scripts.Add(sref); } } //add blacklisted js path's to the script collection individually foreach (var path in postponedList) { Scripts.Add(new ScriptReference(path)); } } }