

Class @ResourceReference@ allows to specify the resources it depends on overriding method @getDependencies()@. The method returns an iterator over the set of @HeaderItems@ that must be rendered before the resource referenced by @ResourceReference@ can be used. This can be really helpful when our resources are JavaScript or CSS libraries that in turn depend on other libraries.

For example we can use this method to ensure that a custom reference to JQueryUI library will find JQuery already loaded in the page: 

{code}
Url jqueyuiUrl = Url.parse("https://ajax.googleapis.com/ajax/libs/jqueryui/" + 
                                                                 "1.10.2/jquery-ui.min.js");
		
UrlResourceReference jqueryuiRef = new UrlResourceReference(jqueyuiUrl){
	@Override
	public Iterable<? extends HeaderItem> getDependencies() {
		Application application = Application.get();
		ResourceReference jqueryRef = application.getJavaScriptLibrarySettings(). 
                                             getJQueryReference();
				
		return Arrays.asList(JavaScriptHeaderItem.forReference(jqueryRef));
	}
};
{code}

Please note that in the code above we have built a resource reference using a URL to the desired library instead of a package resource holding the physical file.

The same method @getDependencies()@ is defined also for class @HeaderItem@.