Class AddPageResources

All Implemented Interfaces:
Future<Void>, Associator, Eligible

public class AddPageResources extends ConsoleCommand
Adds <link …/>, <style>...</style> or <script ...></script> nodes to the web console’s <head> node on behalf of components that provide such resources.

Adding resource references causes the browser to issue GET request that (usually) refer to resources that are then provided by the component that created the AddPageResources event.

The sequence of events is shown in the diagram.

WebConsole Ready Event Sequence

See ResourceRequest for details about the processing of the PageResourceRequest.

The GET request may also, of course, refer to a resource from another server and thus not result in a PageResourceRequest.

Adding a <script src=...></script> node to a document’s <head> causes the referenced JavaScript to be loaded asynchronously. This can cause problems if a dynamically added library relies on another library to be available. Script resources are therefore specified using the AddPageResources.ScriptResource class, which allows to specify loading dependencies between resources. The code in the browser delays the addition of a <script> node until all other script resources that it depends on are loaded.

Some libraries provided as page resources may already be required by the JavaScript web console code (especially by the resource manager that handles the delayed loading). They can therefore not be loaded by this mechanism, which depends on the web console code. Such page resources may be “pre-loaded” by adding the appropriate script element to the initial web console page. In order to make the pre-loading known to the resource manager, the script elements must carry an attribute data-jgwc-provides with a comma separated list of JavaScript resource names provided by loading the script resource. The name(s) must match the name(s) used in the AddPageResources request generated by the PageResourceProvider for the pre-loaded resource(s). Here’s an example (for a web console using the FreeMarkerConsoleWeblet to generate the initial web console page):

<script data-jgwc-provides="jquery"
  src="${renderSupport.pageResource('jquery/jquery' + minifiedExtension + '.js')}">