How to bundle the JS loaded by script manager from CDN in Asp.Net

996 Views Asked by At

I have an application in asp.net, I am using a script manager in master page. I want to load all the scripts related to script manager from CDN and hence I have placed EnableCDN="true" in script manager.

<asp:ScriptManager runat="server" EnableCdn="true" />

I have noticed that all the scripts are loaded separately this increases the http requests, I want to bundle all of them into 1 script.

Has anyone achieved this bundling the scripts loaded from CDN into 1 js file instead of separate in asp.net(Not MVC)?

Below is the snap of all js that is getting loaded separately Below is the snap of all js that is getting loaded separately

1

There are 1 best solutions below

0
ElasticCode On

Only application relative URLs (~/url) are allowed to be included in ScriptBundle, Using CDN in bundles is supported only at the top bundle level.

You could upload the entire bundle to a CDN after building it yourself and us it like https://ajax.aspnetcdn.com/ajax/4.6/1/MsAjaxJs.js.

bundles.Add(new ScriptBundle("~/bundles/MsAjaxJs", "https://ajax.aspnetcdn.com/ajax/4.6/1/MsAjaxJs.js").Include(
    "~/Scripts/WebForms/MsAjax/MicrosoftAjax.js",
    "~/Scripts/WebForms/MsAjax/MicrosoftAjaxApplicationServices.js",
    "~/Scripts/WebForms/MsAjax/MicrosoftAjaxTimer.js",
    "~/Scripts/WebForms/MsAjax/MicrosoftAjaxWebForms.js"));

Also, optimizations are enabled when compilation is set to false in web.config file