Skip to content
Lachlann Rattray edited this page Nov 8, 2018 · 4 revisions

Rendering certain dependencies with different providers

In the config you will notice that there are a few differnet providers. CDF allows you to render certain dependencies with different providers. By default all dependencies will be rendered with the default providers configured.

What is a provider ?

There are 2 types of providers, one type is for MVC and the other is for Webforms. The MVC provider base class is BaseRenderer, the Webforms provider base class is WebFormsFileRegistrationProvider. Both provider types share the same functionality: They are the classes that render the script and link tag output.

You can also create your own providers if you have a specific, currently un-supported way of rendering scripts or styles.

Why do I want this?

In some cases you might want your script or link tags to be rendered differently or in different locations on the page. In either of these cases you can force certain dependencies to render with the non-default provider.

One example is if you wanted to render a specific JavaScript file with the OOTB lazy load provider which will asynchronously go and fetch the JavaScript file from the server and load it into the DOM.

Example in MVC:

@{Html.RequiresJs(new JavascriptFile("~/Js/SomeLazyLoadScript.js") { ForceProvider = "LazyLoadRenderer" }); }

@Html.Raw(Html.RenderJsHere("LazyLoadRenderer"))

Example in Webforms:

<CD:JsInclude runat="server" FilePath="~/Js/SomeLazyLoadScript.js" ForceProvider="LazyLoadProvider"  />

NOTE: that the provider names between MVC and Webforms will be different which you can see in the CDF configuration.

Clone this wiki locally