Created
June 14, 2011 03:20
-
-
Save erikvold/1024242 to your computer and use it in GitHub Desktop.
A include() function for restartless Firefox add-ons
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Includes a javascript file with loadSubScript | |
* By Erik Vold <erikvvold@gmail.com> http://erikvold.com/ | |
* | |
* @param src (String) | |
* The url of a javascript file to include. | |
*/ | |
(function(global) global.include = function include(src) { | |
var o = {}; | |
Components.utils.import("resource://gre/modules/Services.jsm", o); | |
var uri = o.Services.io.newURI( | |
src, null, o.Services.io.newURI(__SCRIPT_URI_SPEC__, null, null)); | |
o.Services.scriptloader.loadSubScript(uri.spec, global); | |
})(this); |
I'm pretty certain Mozilla's main motivation for creating the bootstrap.js
is solely to support restartless addons as best they could design such a thing at the time.
bootstrap.js
files have to be evaluated during startup (if enabled) which I suspect would diminish startup times for most addons by default. Since most old school addons usually only evaluate code after a chrome window has been overlayed.
Sync code is worse than async code though, and Mozilla is trying converting to the latter style quite a bit, mainly because it will/might be required for e10s. But this doesn't have much to do with bootstrap.js
.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I didn't consider the second part, but that's very true.
My reflection on the "core idea" was referring to Mozilla's reasons behind bootstrap.js and the new way of registering, not an individual add-on developer's motivation for using the system devised. Us add-on developers will probably always stick to whichever paved path we find that works for us. :-)
(Just in case it isn't obvious from my question, I am not insinuating being right, but trying to verify whether I had understood their underlying motives right, and if this synchronous way slightly veers in the other direction or is entirely inconsequential.)