-
-
Notifications
You must be signed in to change notification settings - Fork 65
Priorities
There will be cases where you will need some dependencies to be rendered before others. CDF supports this by specifying an integer on any of your dependencies and the output will be ordered accordingly.
CDF preserves the order in which dependencies were registered. If multiple dependencies are registered on the same component and they do not specify an explicit priority, CDF will ensure that these dependencies are rendered in the order they were received. For example, if on a component we register 3 dependencies:
@{
Html.RequiresJs("~/Js/Js1.js")
.RequiresJs("~/Js/Js2.js")
.RequiresJs("~/Js/Js3.js)
}
CDF will ensure that the order the files are rendered is: Js1, Js2, Js3
When an explicity priority is not defined, the default priority is "100". CDF treats a lower number as a higher priority so setting a priority of "1" for example will mean that the dependency will be rendered first.
This will register jquery with a priority of "1" (a high priority)
@{Html.RequiresJs("~/Js/jquery.js", 1)}
This will register jquery with a priority of "1" (a high priority)
<CD:JsInclude runat="server" FilePath="~/Js/jquery.js" Priority="1" />
In some cases a dependency will be registered more than once during the page rendering process. This could be due to different components registering the same dependency. In this case the dependency with the highest priority will be used.