Digging inside the code of module mediawiki (and mediawiki.base), I found out the "load+execute script, then callback" code is actually very simple, see:
function addScript( src, callback ) {
var script = document.createElement( 'script' );
script.src = src;
script.onload = script.onerror = function () {
if ( script.parentNode ) {
script.parentNode.removeChild( script );
}
script = null;
if ( callback ) {
callback();
callback = null;
}
};
document.head.appendChild( script );
}
A few notes about the code:
- The two
= null
are for performance, to free memory (otherwise the objects would stay in memory forever)
- The
onerror
event is not for request error, but for script execution error
So, I think the best solution would be to reuse the above snippet as standalone. Lightweight, no dependency of any kind :)