Page MenuHomePhabricator

Provide an API for external JavaScript source load
Closed, DuplicatePublic


Don't know if that is intentional (due to some policy) but am asking, can you provide or extend mw.loader.load('URL') API to return promise (or there is another for this already?)? See T215280 for example as I couldn't use the source directly I had to directly use

function loadScriptAsync(uri) {

return new Promise(function (resolve, reject) {

		var tag = document.createElement('script');
		tag.src = uri;
		tag.async = true;
		tag.onload = resolve;
		var firstScriptTag = document.getElementsByTagName('script')[0];
		firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);



To load my script on which easily can be written using $.Deferred in order to have compatibility with pre-ES6 we engines. Thanks!

Event Timeline

Ebrahim renamed this task from Provide promise for external source load to Provide an API for external JavaScript source load.Feb 5 2019, 4:11 PM

Quick summary of current state:

  • mw.loader.load() supports URLs but doesn't return a promise
  • mw.loader.using() returns a promise, but doesn't support URLs

This task could be resolved by either adding a promise return to load(), or adding support for URLs to using().

Task T27962 proposes the latter, so I'll merge them. (There is also a recently submitted patch there!)

@Ebraminio The solution for today is as follows:

- var promise = loadScriptAsync( 'https://my.test/url.js' );
+ var promise = $.ajax('https://my.test/url.js', { dataType: 'script', cache: true });