Web Resources - all being loaded

Hi,
I have my web resources separated for different servlet pages in my plugin. Before upgrading my Atlassian Plugin SDK from v 6.2.9 to v 6.2.15 and my Jira version from Jira 7.something to Jira 7.2.1, my web resources loaded okay i.e. my ‘leave’ page would load only its resources and my ‘Adjust’ page would only load its resources. Now, it seems all my resources are being loaded on all my pages and I’m finding errors, for example, my leave page is calling a javascript function in my adjust.js file.
I have my resources listed as follows in my atlassian-plugin.xml file:

<web-resource key="calendar-resources" name="Calendar Resources">
  	<transformation extension="js">
  		<transformer key="jsI18n"/>
  	</transformation>
    <dependency>com.atlassian.auiplugin:ajs</dependency>
    <dependency>com.atlassian.auiplugin:jquery-ui-other</dependency>
    <dependency>com.atlassian.auiplugin:aui-experimental-tooltips</dependency>
    <dependency>com.atlassian.auiplugin:aui-experimental-expander</dependency>
    <dependency>com.atlassian.auiplugin:aui-select</dependency>
    <dependency>com.atlassian.auiplugin:aui-date-picker</dependency>
    <resource type="download" name="icons.css" location="css/icons.css"/>
    <resource type="download" name="leave-common.css" location="css/leave-common.css"/>
    <resource type="download" name="leave.css" location="css/leave.css"/>
    <resource type="download" name="common.js" location="js/common.js"/>
    <resource type="download" name="plannercommon.js" location="js/plannercommon.js"/>       
    <resource type="download" name="planner.js" location="js/planner.js"/>       
    <resource type="download" name="images/" location="css/images"/>
    <resource type="download" name="MaterialIcons-Regular.eot" location="css/MaterialIcons-Regular.eot"/>
    <resource type="download" name="MaterialIcons-Regular.ttf" location="css/MaterialIcons-Regular.ttf"/>
    <resource type="download" name="MaterialIcons-Regular.woff" location="css/MaterialIcons-Regular.woff"/>
    <resource type="download" name="MaterialIcons-Regular.woff2" location="css/MaterialIcons-Regular.woff2"/>
    <context>atl.general</context>
  </web-resource>  
  <web-resource key="adjust-resources" name="Leave Adjust Resources">
  	<transformation extension="js">
  		<transformer key="jsI18n"/>
  	</transformation>  	
    <dependency>com.atlassian.auiplugin:ajs</dependency>
    <dependency>com.atlassian.auiplugin:jquery-ui-other</dependency>
    <dependency>com.atlassian.auiplugin:aui-experimental-tooltips</dependency>
    <dependency>com.atlassian.auiplugin:aui-experimental-expander</dependency>   
    <resource type="download" name="jquery.ui.theme.css" location="css/jquery.ui.theme.min.css"/>    
    <resource type="download" name="icons.css" location="css/icons.css"/>
    <resource type="download" name="leave-common.css" location="css/leave-common.css"/>
    <resource type="download" name="adjust.css" location="css/adjust.css"/>
    <resource type="download" name="leave.css" location="css/leave.css"/>
    <resource type="download" name="common.js" location="js/common.js"/>
    <resource type="download" name="plannercommon.js" location="js/plannercommon.js"/>            
    <resource type="download" name="adjust.js" location="js/adjust.js"/>    
    <resource type="download" name="images/" location="css/images"/>
    <resource type="download" name="MaterialIcons-Regular.eot" location="css/MaterialIcons-Regular.eot"/>
    <resource type="download" name="MaterialIcons-Regular.ttf" location="css/MaterialIcons-Regular.ttf"/>
    <resource type="download" name="MaterialIcons-Regular.woff" location="css/MaterialIcons-Regular.woff"/>
    <resource type="download" name="MaterialIcons-Regular.woff2" location="css/MaterialIcons-Regular.woff2"/>
    <context>atl.general</context>
  </web-resource>

And in my individual velocity templates, they load the web resource packages using the appropriate key:

The leave page uses:

$webResourceManager.requireResource("my.company.jira.plugin.leave:calendar-resources") 

and the Adjust page uses:

$webResourceManager.requireResource("my.company.jira.plugin.leave:adjust-resources")

Looking at the batch.js in F12 developer tools in the browser, confirms the adjust.js is being loaded when the leave page is requested, which should not happen.

Has anyone else seen this or I’m I doing something incorrect here?
Thanks.

You’re referencing the atl.general context which will cause your web resources to be loaded on every page.

Thanks Daniel,

So what you’re saying is that the context decides on where my web resources get loaded - so I shouldn’t have to use the $webResourceManager.requireResource() statement in my velocity template?

No, the opposite: remove the <context>atl.general</context> from both of your web-resources.

When you add a context to a web-resource, you’re saying “please implicitly load these resources on every set of pages that use this context”. The atl.general context is loaded on practically every page in JIRA. The net effect: both your resources are being loaded on every single page in JIRA – this is why you’re seeing the extraneous resource.

Because you’re explicitly loading your web-resources on your pages, you don’t want a context. So, just remove that and things will work as expected.

I would also recommend extracting the common assets between your web-resources in to another web-resource; this will allow Jira to batch and load the resources more effectively.

Awesome! Thanks Daz.

What @daz said.

You might also want to consider creating your own “context” (you can just specify it in the tags). Then in the webResourceManager you can call requireResourcesForContext and pass in the context.

This way you can have multiple web-resource entries in your atlassian-plugin.xml (but don’t go overboard - “with much power comes great responsibility”).

If you create your own context - prefix it with a guaranteed unique string (company/addon name is a good approach).

Thanks for the context tip Daniel.