Absolute URL in ASP bundle

前端 未结 6 791
轻奢々
轻奢々 2021-01-07 19:14

I use a jQuery library for Google Maps, and it depends on the Google scripts to be loaded first. I\'d like to be able to include both in the bundle as such:

         


        
6条回答
  •  被撕碎了的回忆
    2021-01-07 19:30

    If you are using a version of System.Web.Optimization >= 1.1.2, there is a new convenient way of overriding the url's for Styles and Scripts. In the example below, I am grabbing a CdnBaseUrl from web.config to use as the base url for all scripts and stylesheets:

    public class BundleConfig
    {
        private static readonly string BaseUrl = ConfigurationManager.AppSettings["CdnBaseUrl"];
    
        public static void RegisterBundles(BundleCollection bundles)
        {
            // This is the new hotness!!
            Styles.DefaultTagFormat = "";
            Scripts.DefaultTagFormat = "";
    
            bundles.Add(new ScriptBundle("~/bundles/js").Include(
                "Your scripts here..."
            ));
    
            bundles.Add(new StyleBundle("~/bundles/css").Include(
                "Your css files here..."
            ));
        }
    }
    

    More info on static site (CDN) optimization

提交回复
热议问题