开发者

How to manage javascript Dependency for Ajax Extender controls

Does the Ajax Extender control base provide dependency management? I am creating a set of controls that uses a few base scripts used by the behaviors and from here Creating a Extender Control it sort of looks i will have to include my base script in every single control code. So does the extender base serve the same script[a cached o开发者_Go百科ne] for each control or same script is served for each control.

For example i am developing controls that depend on jQuery. Since i am developing extender controls i will have to implement this method from the interface like below, notice the jquery script!

protected override IEnumerable<ScriptReference> GetScriptReferences()
{
    ScriptReference reference = new ScriptReference();
    reference.Path = ResolveClientUrl("jQuery.js");
    reference.Path = ResolveClientUrl("FocusBehavior.js");
    return new ScriptReference[] { reference };
}

now i will have same jquery script in another control, so does this mean they are served twice if both control are in same page? Also another question,

How do make the extender control output the production scripts instead of the debug scripts Also registering script with scriptmanager is not a option for me as i use masterpage that doesn't need a script manager.

Some Specs:

Developed in VS2005

.NET 2.0, ASP.NET 2.0

Script Dependency on Sizzle, emile.js, spine.js these are base scripts required for all controls


I believe the ASP.NET framework does properly handle duplicate ScriptReference objects in its rendering process since ASP.NET controls can exist in multiple instances on your page.

For example, in an ASP.NET page you can do:

<act:Calendar runat="server" ID="calendar1"/>
<act:Calendar runat="server" ID="calendar2"/>

both of those controls rely upon the same scripts, but the framework doesn't load them twice.

In your situation, you would probably want to do something like:

protected override IEnumerable<ScriptReference> GetScriptReferences()
{
    List<ScriptReference> references = new List<ScriptReference>();

    #if DEBUG
    // Load Debug Version
    references.Add(new ScriptReference(ResolveClientUrl("~/Path_To_Your_Debug_JS.js"));     
    #else
    // Load Minified Version
    references.Add(new ScriptReference(ResolveClientUrl("~/Path_To_Your_Release_JS.js"));
    #endif

    return references;
}

This should allow you to serve either the Debug or Release(minified) versions of your Javascript files depending upon being in either Debug or Release modes.

I'm not sure about your comment about your MasterPage not needing a ScriptManager. I'll assume that you have some sort of mechanism that deals with handling the responsibilities of the ScriptManager like calling the GetScriptReferences() method on your controls and handling the rendering of those script tags.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜