View Source

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:

h3. 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.
{code:xml}
<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>
{code}

h3. 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.
{code:xml}
<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>
{code}


Attributes:
* name
bq. the file name of the resource
* library
bq. 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
bq. 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:

{code:xml}
<?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>
{code}

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