Hi,
what is the recommend way to import JavaScript code modules in files
part of Gecko?
1) Don't add the import line
Components.utils.import("resource://app/my_module.jsm"); into the file
if the module has already been loaded by a different JavaScript file
load earlier.
Advantage: Fastest
Disadvantage: If the other file drops the jsm, the code will break. The
developer will have to find the issue if the file requiring the jsm gets
loaded into a different scope and won't work (e.g. by an extension).
2) Conditional loading by checking if the exported symbol(s) exist:
if (!exportedSymbol)
Components.utils.import("resource://app/my_module.jsm");
3) Add the import line on top of the file:
Components.utils.import("resource://app/my_module.jsm");
https://developer.mozilla.org/en-US/docs/JavaScript_code_modules/Using
reads:
"An extremely important behavior of Components.utils.import() is that
modules are cached when loaded and subsequent imports do not reload a
new version of the module, but instead use the previously cached version."
So are 2) and 3) nearly equivalent regarding performance? What is the
recommend way to import a JavaScript module?
Thank you
Archaeopteryx
_______________________________________________
dev-platform mailing list
[email protected]
https://lists.mozilla.org/listinfo/dev-platform