linkPlugin API Reference Documentation: Appendix IV: Loading external libraries
The plugin execution context is isolated so it can loosen restrictions the application imposes on loading external resources. There are a couple patterns that can be used in plugin code to load external dependencies, depending on how the dependency is packaged.
linkLoading browser builds
The simplest dependency to load is a library that has a browser build. This is a build that can normally be used in a <script> tag - in plugin code a script tag can be appended to the document to load the dependency.
For example, to load the RecordRTC library's browser build:
A couple things to note in the above code:
The plugin execution context is kept loaded, so the dependency doesn't need to be loaded on every single call to the plugin - only the first call.
The library in question - RecordRTC - will be available as window.RecordRTC because it is packaged up as a browser build.
This can be used in the plugin's actions as:
linkLoading UMD builds
Dependencies that define UMD modules can be loaded with a small code shim:
Given a dependency that provides a UMD build, the above helper can be used as: