asp.net - Loading AjaxControlToolkit Scripts from Microsoft's CDN using ScriptManager/ToolkitManager -
i know there question asking same thing, hasn't gotten attention months now: https://stackoverflow.com/questions/3786088/how-to-force-ajax-control-toolkit-scripts-loading-from-cdn
i've upgraded website .net4, , i'm using scriptmanager's enablecdn="true" tag. ajax scripts being referenced microsoft cdn how expected, can't seem ajaxcontroltoolkit scripts load cdn. instead load locally through scriptresource.axd.
i know cdn files located, , know reference files every time use control, i've got lot of legacy code loads on own scriptmanager, pulling scriptresource.axd files.
any suggestions how control toolkit scripts load cdn? have standard webforms.js, etc.
let me know if there can clear up, here script manager i'm using: (i have tried toolkitscriptmanager)
<asp:scriptmanager id="scriptmanager1" runat="server" enablepagemethods="true" enablecdn="true" enablescriptlocalization="false" loadscriptsbeforeui="false" enableviewstate="false" />
if assembly not define cdn path in webresourceattributes, enablecdn won't know go. there's that.
however, can define own cdn path if know of cdn has them. don't know whether latest act on cdn or not. if version using 40412, yes, is: http://www.asp.net/ajaxlibrary/cdnact40412.ashx
the way define own path described in blog entry (also mentioned in answer):
http://weblogs.asp.net/infinitiesloop/archive/2009/11/23/asp-net-4-0-scriptmanager-improvements.aspx
here's example, explained below:
void application_start(object sender, eventargs e) { scriptmanager.scriptresourcemapping.adddefinition("foo.js", typeof(foocontrol).assembly, new scriptresourcedefinition { resourcename = "foo.js", resourceassembly = typeof(foocontrol).assembly, cdnpath = "http://yadda-yadda/foo.js", cdndebugpath = "http://yadda-yadda/foo.debug.js", }); }
here happening. first of all, there exists assembly, lets call foo.dll. contains script embedded resource named "foo.js" (the .js extension optional). so, asp:scriptreferences (on page or coming server control) resource go scriptresource.axd. assembly's webresourceattribute script not define cdn path, still goes there if turn on cdnmode.
you want fix that, target script. so, have refer assembly , name. together, identify script (it's "primary key", if will). 1st 2 parameters adddefinition accomplish that.
now targetted it, redefine means script. put in assembly, path, define cdn path.. anything.
the resourcename , resourceassembly properties of definition establish script still belongs same assembly came from. might seem unnecessary if going load cdn anyway. 2 things: (1) still work if turn off cdn, , (2) still able figure out if debug version of resource (foo.debug.js) or localized versions (e.g. foo.fr-fr.js) exist in assembly, , thereby know whether cdn contain version (since can't check server). it's idea give definition owner (note not default original owner if don't specify them).
the cdnpath , cdndebugpath properties obvious, , ultimate goal here. enablecdn should work!
i encourage use scriptmapping when possible define details script , refer them name instead of path. keeps markup simple , it's more dry since define details script in 1 place.
now... how do ajaxcontroltoolkit?
you're going have write 1 of these mappings each , every script in toolkit. not going fun, there dozens , dozens of them. don't make mistake of writing separate ones each release , debug script though. 2 pair , defined 1 mapping. there localized versions of of them, wouldn't bother -- messages error messages meant developers, don't need localized anyway, because feature meant localize content end users.
one thing -- try out on 1 or 2 of act scripts make sure got right. also, there's 1 more complexity here didn't mention.
remember when said name , assembly come identify script (its "primary key")? that's true, there's 1 special rule scripts come system.web.extensions or so-called "ajaxframeworkassembly". in case, specifying null assembly, or using overload parameter missing altogether, equivalent. "ajaxframeworkassembly"? well, system.web.extensions contains little-known feature allows assembly assert "ajaxframeworkassembly" via assembly level attribute. doing means "i assembly contains ms ajax scripts, should come me instead of system.web.extensions". act uses in order 'upgrade' scripts embedded in system.web.extensions. has own copies of scripts have later version number. have reference assembly, , presto, scripts automatically redirected come there instead. point here being, may able away not specifying assembly in of mappings. but, try out, don't take word it.
this has been infinitiesloop answer. return regularly scheduled programming :)
Comments
Post a Comment