This page last changed on Oct 22, 2009 by rosie@atlassian.com.

JIRA plugins may define downloadable resources. If your plugin requires JIRA to serve additional static Javascript or CSS files, you will need to use downloadable web resources to make them available. Web resources differ from Downloadable Plugin Resources in that web resources are added at the top of the page in the header.

This is only available as of JIRA 3.7 and above.

Purpose of this Module Type

Web Resource plugin modules allow plugins to define downloadable resources. If your plugin requires the application to serve additional static Javascript or CSS files, you will need to use downloadable web resources to make them available. Web resources are added at the top of the page in the header with the cache-related headers set to never expire. In addition, you can specify web resources like CSS and JavaScript to be included in specific contexts within the application.

Configuration

The root element for the Web Resource plugin module is web-resource. It allows the following attributes and child elements for configuration:

Attributes

Name Required Description Default
class   The class which implements this plugin module. The class you need to provide depends on the module type. For example, Confluence theme, layout and colour-scheme modules can use classes already provided in Confluence. So you can write a theme-plugin without any Java code. But for macro and listener modules you need to write your own implementing class and include it in your plugin. See the plugin framework guide to creating plugin module instances.  
disabled   Indicate whether the plugin module should be disabled by default (value='true') or enabled by default (value='false'). false
i18n-name-key   The localisation key for the human-readable name of the plugin module.  
key The identifier of the plugin module. This key must be unique within the plugin where it is defined.
Sometimes, in other contexts, you may need to uniquely identify a module. Do this with the complete module key. A module with key fred in a plugin with key com.example.modules will have a complete key of com.example.modules:fred. I.e. the identifier of the web resource.
N/A
name   The human-readable name of the plugin module. I.e. the human-readable name of the web resource. The plugin key
system   Indicates whether this plugin module is a system plugin module (value='true') or not (value='false'). Only available for non-OSGi plugins. false

Elements

Name Required Description Default
description   The description of the plugin module. The 'key' attribute can be specified to declare a localisation key for the value instead of text in the element body. I.e. the description of the resource.  
resource A resource for this plugin module. This element may be repeated. A 'resource' is a non-Java file that a plugin may need in order to operate. Refer to Adding Plugin and Module Resources for details on defining a resource.Currently, supported file types are .css and .js.
For web resources, the type attribute must be 'download'.
N/A
dependency
  Dependencies for the web resource module. A web resource can depend on other web resource(s) to be available. Dependencies are defined in the format 'pluginKey:webResourceKey' e.g. <dependency>confluence.web.resources:ajs</dependency>
Note: This element is only available in Plugin Framework 2.2 and later.
N/A
context   Use this element to include web resources like CSS and JavaScript on all screens of a specific type in the application. See below.
Note: This element is only available in Plugin Framework 2.5 and later.
 
transformation   Use this element to make a particular transformer available to the web resource in the plugin. Example:

For a complete description, please refer to the page on Web Resource Transformer Plugin Modules.
Note: This element is only available in Plugin Framework 2.5 and later.

 
condition   Use this element to define when this web resource should display or not.  See Web Item Conditions for more information.
Note: This element is only available in Plugin Framework 2.7 or later.
 

Example

Here is an example atlassian-plugin.xml file containing a single web resource:

Referring to Web Resources

In your plugin, you need to refer to a WebResourceManager and call the requireResource() method. The reference to WebResourceManager can be injected into your constructor:

Web Resource Contexts

In version 2.5 and later of the Plugin Framework, you can automatically include web resources like CSS and JavaScript on all screens of a specific type in the application. These are called 'web resource contexts'. The currently available contexts are:

Context Description
atl.general Everywhere except administration screens
atl.admin Administration screens. Use with care because poorly formed CSS or JavaScript can prevent access to administering the application.
atl.userprofile User profile screens.

The above contexts are applicable to all Atlassian applications. In addition to these application-independent contexts, each Atlassian application can also supply its own application-specific contexts.

Example: To configure your web resource to be included in every page (both administration and non-administration pages), add <context> child elements to your <web-resource> element in your atlassian-plugin.xml:

Using web resource contexts allows you to provide plugins that dynamically create HTML using JavaScript on any page in the application. For example, the Confluence Content Navigation Plugin includes a snippet of JavaScript on every page in the application, which listens for a particular keyboard shortcut to open a little search box on top the Confluence UI.

Introducing new contexts

If your plugin adds a number of screens to the application, you may find it useful to introduce a new web resource context for your plugin that your plugin web resources (or any other plugin web resource) can hook into, to be automatically included on these screens.

To introduce a new context in your plugin Velocity templates, you can call the requireResourcesForContext() method on the WebResourceManager object from your Velocity templates:

This will include any resource in the page that specifies a context like this in its definition: <context>com.acme.plugin.fancy-context</context>.

We recommend that you namespace your new contexts in this way so as not to clash with any future contexts in the applications themselves or in other plugins.

Batched Mode

The default mode for serving web resources in Plugin Framework 2.2 is batched mode. Batched mode refers to the serving of multiple plugin resources (of the same type) in one request. For example, the two scriptaculous web resources defined above would be served in one request, containing both scriptaculous.js and effects.js. Hence, batching reduces the number of HTTP requests that web browsers need to make to load a web page.

URLs for batched resources are in the following format:

For the above scriptaculous example, the following code will be inserted in the header of the page:

Non-Batched Mode

Prior to Plugin Framework 2.2, each resource defined was served separately. To revert to this non-batched mode, you can either

  • use the system property plugin.webresource.batching.off=true to turn off batching system wide
  • or define a 'batch' parameter on each resource like so:

URLs for non batched resources are in the following format:

For the above scriptaculous example with batching turned off, the following code will be inserted in the header of the page:

Transforming Web Resources

Transformers are only available in Plugin Framework 2.5 and later.

The plugin framework provides web resource transformers that you can use to manipulate static web resources before they are batched and delivered to the browser.

To use a web resource transformer, you need the following elements in your atlassian-plugin.xml file:

  • The transformer module: A <web-resource-transformer> element, defining the transformer plugin module. This module can be in the same plugin as the web resource, or in a different plugin.
  • Transformation elements in the web resource module: A <transformation> element and its child <transformer> element inside the <web-resource> block, making a particular transformer available to the web resource in the plugin.

For a complete description and example, please refer to the page on Web Resource Transformer plugin modules.

Notes

  • Since the resources are returned with headers that tell the browser to cache the content indefinitely, during development, you may need to hold down the "shift" key while reloading the page to force the browser to re-request the files.
Document generated by Confluence on Mar 27, 2011 18:53