Resource dependencies

Table of Contents

Resource dependencies can be declared in ICEfaces to make sure the resources are loaded in the correct order. This feature is used in core, components and can be used for application resources as well.

The dependencies are declared in an XML file that is expected to be packaged within the library (jar), under META-INF/resource-dependency.xml path.

Each resource can declare its dependency to other resources. There are two types of dependencies:

1. <requires>

(since 4.0)

The requires tag can be used to mark the resources that are required to be loaded before the defined resource. Specifying a resource as required will result in the resource being automatically loaded in the order prescribed by the resource-dependency.xml file(s). Using the requires tag is useful in cases where a resource is required on every page.

For example, B.js, C.js will be loaded before A.js if there are components in the page needing them. D.js will be loaded before A.js, regardless of the requirements components have.

<resource name="A.js" library="A-lib" target="head">
        <depends-on>
            <resource name="B.js" library="x" target="head"/>
            <resource name="C.js" library="x" target="head"/>
        </depends-on>
        <requires>
            <resource name="D.js" library="x" target="head"/>
        </requires>
</resource>

2. <depends-on>

(since 3.3)

Resources enclosed in a depends-on tag are not automatically loaded by the resource dependency subsystem, but when present on the page they will be loaded before the declared resource. That is, they must be loaded by the application when applicable, such as via an h:outputStylesheet or h:outputScript tag. When these resource are included on a page, they will be loaded in the order prescribed by the resource-dependency.xml file(s). Using the depends-on tag is useful in cases where it may not always be desirable to load a particular resource (on every page), but when it is present, it must be loaded in a prescribed order.

For example, B.js, C.js will be loaded before A.js. In case B.js or C.js are not required by any of the components in the page, A.js will still be loaded but without forcing the loading of its dependencies.

<resource name="A.js" library="A-lib" target="head">
        <depends-on>
            <resource name="B.js" library="x" target="head"/>
            <resource name="C.js" library="x" target="head"/>
        </depends-on>
</resource>

Attributes:

  • name

    the file name of the resource

  • library

    The JSF library name where the resources can be found. The attribute is optional. When not provided the library name is assumed to be the empty string.

  • target

    The target element where resource is expected to be referenced. The attribute is optional. When not provide the "head" value is assumed.

The META-INF/resource-dependency.xml file can contain multiple dependencies all found under the same root element:

<?xml version="1.0"?>
<dependencies>
    <resource name="a.js">
        <requires>
            <resource name="jsf.js" library="javax.faces"/>
        </requires>
    </resource>
    <resource name="b.js">
        <requires>
            <resource name="jsf.js" library="javax.faces"/>
        </requires>
    </resource>
    <resource name="c.js">
        <requires>
            <resource name="jsf.js" library="javax.faces"/>
        </requires>
        <depends-on>
            <resource name="b.js"/>
            <resource name="a.js"/>
        </depends-on>
    </resource>
    ...
    ...
</dependencies>

ICEfaces will use the information found in all resource-dependency.xml files to order the resources referenced by the rendered page.

Enter labels to add to this page:
Please wait 
Looking for a label? Just start typing.

© Copyright 2018 ICEsoft Technologies Canada Corp.