Topic on Project:Support desk

Is importScript Deprecated?

5
Summary by Johnywhy

It is deprecated but not likely to disappear immediately. importScript is deprecated, because it loads scripts synchronously, whereas every script in MediaWiki should be expecting asynchronous behaviour. As long as your script can handle asynchronous loading, then you shouldn't have a problem. importScript is in a bit of a limbo due to its widespread use, so you can expect to at least find large announcements if at any point it will disappear.

Johnywhy (talkcontribs)

This page explains how to use importScript. But seems to fail on my MW 1.30.

This page has some discussion about deprecation, but seems to conclude that importScript is not deprecated.

This page says to migrate importScript to mw.loader.

The nice thing about importScript is that you can pass a simple page refererence, eg importScript('MyScript.js'). It appears that mw.loader requires a more complicated url-syntax, eg

mw.loader.load( '/w/index.php?title=MyScript.js&action=raw&ctype=text/javascript' );

Is it deprecated, or soon to be?

TheDJ (talkcontribs)

It is deprecated but not likely to disappear immediately. importScript is deprecated, because it loads scripts synchronously, whereas every script in MediaWiki should be expecting asynchronous behaviour. As long as your script can handle asynchronous loading, then you shouldn't have a problem. importScript is in a bit of a limbo due to its widespread use, so you can expect to at least find large announcements if at any point it will disappear.

Johnywhy (talkcontribs)

Seems to me, it's preferable to have a choice between synchronous and asynchronous. No?

TomT0m (talkcontribs)

Is it possible to create a form of the « loader » function that takes a pagename instead of a uri on a local wiki ? The url can be computed easily if needed.

Tacsipacsi (talkcontribs)

@TheDJ: People seem to refer to this topic now, five years later, so I’ll summarize why what you said doesn’t stand today:

  • ResourceLoader/Migration guide (users) no longer marks importScript/importStylesheet as deprecated (diff), only their URI variants.
  • I don’t know if this was different half a decade ago, but now both importScript and mw.loader.load end up calling mw.loader.addScript. Same function, same behavior in regard to synchronicity. The only difference is that mw.loader.load returns a promise you can await, but the fact that you cannot wait for the result of importScript doesn’t make it more synchronous, the current script is not halted while the other script is downloaded and compiled.
Reply to "Is importScript Deprecated?"