JIRA 4.0 : Web Resource Plugin Module
This page last changed on Sep 28, 2009 by mlassau.
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. 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: <atlassian-plugin name="Hello World Resource" key="example.plugin.helloworld" plugins-version="2"> <plugin-info> <description>A basic web resource module test</description> <vendor name="Atlassian Software Systems" url="http://www.atlassian.com"/> <version>1.0</version> </plugin-info> <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" /> </web-resource> </atlassian-plugin> 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: public MyServlet extends HttpServlet { private WebResourceManager webResourceManager; public MyServlet(WebResourceManager webResourceManager) { this.webResourceManager = webResourceManager; } protected final void doGet(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) throws IOException { webResourceManager.requireResource("example.plugin.helloworld:scriptaculous"); //should be the full module key for the <webreference> module. // more code } } Batched ModeThe default mode for serving web resources in Plugins 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 fomat: SERVER_ROOT/s/BUILD_NUM/PLUGIN_VERSION/SYSTEM_COUNTER/_/download/batch/js/PLUGIN_KEY:MODULE_KEY/BATCHNAME.js SERVER_ROOT/s/BUILD_NUM/PLUGIN_VERSION/SYSTEM_COUNTER/_/download/batch/css/PLUGIN_KEY:MODULE_KEY/BATCHNAME.css For the above scriptaculous example, the following code will be inserted in the header of the page: <script type="text/javascript" src="http://jira.example.com/s/170/1.0/1/_/download/batch/js/jira.extra.impresence:scriptaculous/jira.extra.impresence:scriptaculous.js"></script> Non-Batched ModePrior to Plugins 2.2, each resource defined was served separately. To revert to this non-batched mode, you can either
<resource type="download" name="scriptaculous.js" location="includes/js/effects/scriptaculous.js" > <param name="batch" value="false"/> </resource> URLs for non batched resources are in the following fomat: SERVER_ROOT/s/BUILD_NUM/PLUGIN_VERSION/SYSTEM_COUNTER/_/download/resources/PLUGIN_KEY:MODULE_KEY/RESOURCE_NAME For the above scriptaculous example with batching turned off, the following code will be inserted in the header of the page: <script type="text/javascript" src="http://jira.example.com/s/170/1.0/1/_/download/resources/jira.extra.impresence:scriptaculous/scriptaculous.js"></script> <script type="text/javascript" src="http://jira.example.com/s/170/1.0/1/_/download/resources/jira.extra.impresence:scriptaculous/effects.js"></script> Notes
|
![]() |
Document generated by Confluence on Oct 06, 2009 00:31 |