Web Resource plugin module


Atlassian Plugin Framework 1.x and later.


Web resource contexts became available in Atlassian Plugin Framework 2.5 and later. Before that they were available in Confluence only, in Confluence 2.10 and later.
Web resource transformers became available in Atlassian Plugin Framework 2.5 and later.
Web resource conditions became available in Atlassian Plugin Framework 2.7 and later.

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.


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





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.


Indicate whether the plugin module should be disabled by default (value='disabled') or enabled by default (value='enabled').

Default: enabled


The localisation key for the human-readable name of the plugin module.


The unique identifier of the plugin module. You refer to this key to use the resource from other contexts in your plugin, such as from the plugin Java code or JavaScript resources.

In the example, appProps is the key for this particular module declaration, for component-import, in this case.

That is, the identifier of the web resource.


The human-readable name of the plugin module. That is, the human-readable name of the web resource.

Default: the plugin key


The location into which this web item should be placed.


Indicates whether this plugin module is a system plugin module (value='true') or not (value='false'). Only available for non-OSGi plugins.

Default: false

*key attribute is required





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. That is, the description of the resource.



Indicate whether the plugin module should be disabled by default (value='disabled') or enabled by default (value='enabled').


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>com.atlassian.auiplugin:ajs</dependency>
Note: This element is only available in Plugin Framework 2.2 and later.


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.


Use this element to make a particular transformer available to the web resource in the plugin. Example:

<transformation extension="txt">
<transformer key="template" />

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.


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.

*resource element is required


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

<atlassian-plugin name="Hello World Resource" key="example.plugin.helloworld" plugins-version="2">
        <description>A basic web resource module test</description>
        <vendor name="Atlassian Software Systems" url="http://www.atlassian.com"/>

    <web-resource key="scriptaculous" name="Scriptaculous" >
        <resource type="download" name="scriptaculous.js" location="includes/js/effects/scriptaculous.js" />
        <resource type="download" name="effects.js" location="includes/js/effects/effects.js" />

Referring to Web Resources

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

public MyServlet extends HttpServlet
    private PageBuilderService pageBuilderService;

    public MyServlet(PageBuilderService pageBuilderService)
        this.pageBuilderService = pageBuilderService;

    protected final void doGet(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) throws IOException
        //should be the full module key for the <webreference> module.
        // more code

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:




Everywhere except administration screens.


Administration screens. Use with care because poorly formed CSS or JavaScript can prevent access to administering the application.


User profile screens.


Browser pop-up windows. This will open a new window for things like OAuth authorisation, and similar purposes.

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:

<web-resource name="Resources" key="resources">
       <resource name="foo.js" type="download" location="resources/foo.js"/>

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:

<script type="text/javascript"

Batched resource URLs do not include any URL path prefixes that were specified in the individual <resource> names. This can cause problems if a resource refers to another resource by a relative URL.

For instance, if your web resource contains a stylesheet with the name "css/styles.css", and that stylesheet uses an image from the same web resource whose name is "images/foo.png", you could use the relative URL ../images/foo.png if batch mode is off; but with batch mode on, the stylesheet will no longer have css/ in its URL, so the relative URL will be wrong. (The absolute URL of the image remains the same, since images are not affected by batching.)

The plugin framework attempts to help by rewriting URLs in stylesheets to be relative to the server root, but there is a known issue that prevents this from working correctly. Therefore, if you do not know whether batch mode will be on or off, avoid using a subpath prefix in the name attribute of any resource that contains relative URL references. In the above example, the stylesheet's name would be simply "styles.css" and the relative image URL would be images/foo.png. The location attribute, since it refers to the location of the actual file before any batching or URL rewriting takes place, does not need to change.

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.


  • 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.

Use this element to make a particular transformer available to the web resource in the plugin. Example:

Web Resource Transformer Plugin Module
Plugin Modules

Rate this page: