1

I'm using includes in my extension.js file and want to be able to nest other include files. For example: I want to include a file 1.js which in turn includes 1-1.js and 1-2.js, and then 1-2.js includes 1-2-1.js and 1-2-2.js. I can use appAPI.resources.includeJS to include one level of files - but I can't seem to use it inside a resource file.

Also, why can't I just directly include files outside of the appAPI.ready callback? i.e. by simply concatenating the JS files.

kokoma k
  • 11
  • 1
  • 1
    Nested includes should work, I'n not sure i've undertstood the 2nd question, if you concat your files you don't need to use includeJS. – Bnaya Sep 15 '14 at 12:29

1 Answers1

2

To answer your second question first, you do not have to use appAPI.resources.includeJS to include JavaScript files and can in fact concatenate all your include files into one file. However, since the file can grow quite quickly, this is not recommended as there is a 150K limit per file.

Regarding nesting include files, this is certainly possible. Take the following example based on your question:

extension.js:

appAPI.ready(function($) {
  appAPI.resources.includeJS('1.js');
});

1.js:

console.log('1.js loaded, now loading 1-1.js & 1-2.js');
appAPI.resources.includeJS('1-1.js');
appAPI.resources.includeJS('1-2.js');
console.log('Done');

1-1.js:

console.log('1-1.js loaded');

1-2.js:

console.log('1-2.js loaded, now loading 1-2-1.js & 1-2-2.js');
appAPI.resources.includeJS('1-2-1.js');
appAPI.resources.includeJS('1-2-2.js');

1-2-1.js:

console.log('1-2-1.js loaded');

1-2-2.js:

console.log('1-2-2.js loaded');

The result in the console:

1.js loaded, now loading 1-1.js & 1-2.js
1-1.js loaded
1-2.js loaded, now loading 1-2-1.js & 1-2-2.js
1-2-1.js loaded
1-2-2.js loaded
Done

[Disclosure: I am a Crossrider employee]

Shlomo
  • 3,763
  • 11
  • 16