It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Call a JavaScript file from another JavaScript File

Hi folks,


I have a requirement where We are supposed to bring our JS file to a modular pattern because of ever growing size in our plugin. The challenge is that we need to call other JS files from the base file, however I am not getting a way. I tried registering the JS file in VM, did AJS.$.getScript  and many other methods which didn't work. I also registered file in the resources, but invoking is not happening.


Here are the two sample JS files


+function(AJS) {
'use strict';
function anyMethod(){
alert("Hello from another file");



+function(AJS) {
'use strict';

function helloWorld(){
alert("Hello from another file");


 I want to invoke the helloWorld of test2.js from test1.js file. Please let me know how should I invoke this.


P.S. We are using this design and changing the design for our JS files is not in the scope. 

1 answer

0 votes

Hi @AnupamS ,

Based on your description, it is unclear how your atlassian-plugin.xml is defined (in case of building an Atlassian add-on). Here is an example on how you should be Including Javascript and CSS resources to your plugin:

  • defining the web-resource, resource and its context
  • requiring the resource on your view, requireResource
  • running scripts when the page loads

If you want to get your plugin more structured you should be looking into Backbone.js. Here is an example:

It is important to notice:

Backbone and Underscore

Backbone and Underscore are not added to window by AUI any more by default. If you depend on these libraries, you must pull in your own.

In Atlassian plugins, it is possible to add them to the window by explicitly requiring their web-resource keys, though this approach is deprecated and will be removed in AUI 9.0.

More information on

Kind regards,

Hi Rafael,

Thank you for your reply.


I am registering the js files in the xml

<web-resource key="sample" name="sample">

<resource type="download" name="test-file1.js" location="/js/test1.js"/>
<resource type="download" name="test-file2.js" location="/js/test2.js"/>



As the context is given, these two files should be loaded to DOM when the issue is on create/edit. I am able to invoke functions of test1.js after binding it as below


JIRA.bind(JIRA.Events.NEW_CONTENT_ADDED, function (event, context, reason) {
//console.warn('##### JIRA.Events.NEW_CONTENT_ADDED', reason);
if (reason == JIRA.CONTENT_ADDED_REASON.dialogReady || reason == JIRA.CONTENT_ADDED_REASON.pageLoad) {


However the ask is to access functions of test2.js from test1.js 


As the context is already defined in the resource, I am able to invoke test1.js without requiring it in the view (vm file). As I am abstracting the actual files, which are pretty large, changing it to some other architect (as you suggested) is not possible at least at this point in time, 



Suggest an answer

Log in or Sign up to answer
Community showcase
Published in Jira

Keep your team in the loop with Team @mentions in Jira Software!

Hi everyone! My name is Jenny, a Product Manager at Atlassian. After launching Team @mentions in Confluence, we heard a lot of positive feedback from customers that they love how easy it is to @men...

557 views 6 18
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you