JIRA 4.3 : Web Resource Plugin Module
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.
Purpose of this Module TypeWeb 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. ConfigurationThe root element for the Web Resource plugin module is web-resource. It allows the following attributes and child elements for configuration: Attributes
Elements
ExampleHere is an example atlassian-plugin.xml file containing a single web resource: Referring to Web ResourcesIn 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 ContextsIn 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:
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 contextsIf 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 ModeThe 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: Non-Batched ModePrior to Plugin Framework 2.2, each resource defined was served separately. To revert to this non-batched mode, you can either
URLs for non batched resources are in the following format: Transforming Web Resources
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:
For a complete description and example, please refer to the page on Web Resource Transformer plugin modules. Notes
|
![]() |
Document generated by Confluence on Mar 27, 2011 18:53 |