Page MenuHomePhabricator

Global JavaScript not loading on some sites
Closed, ResolvedPublic

Description

My global javascript at [[m:User:Hazard-SJ/global.js]] Is only loading on some sites, like [[en:]] and [[commons:]], but not sites like [[simple:]], [[meta:]], and [[testwiki:]] which have been updated to 1.19wmf1.


Version: unspecified
Severity: normal

Details

Reference
bz34482

Event Timeline

bzimport raised the priority of this task from to Medium.Nov 22 2014, 12:09 AM
bzimport set Reference to bz34482.
bzimport added a subscriber: Unknown Object (MLST).

I can load and execute a global.js from meta with just:

alert("hi!");

I suspect there are some Resource Loader problems in your code.

These will need to be fixed, or your code will probably stop working. I suspect the problem is with this function:

function importAnyScript(lang,family,script) {

document.write('<script type="text/javascript" src="' + 'http://'

		+ lang + '.'
		+ family + '.org/w/index.php?title='
		+ script + '&action=raw&ctype=text/javascript"></script>');
  }

You probably want to replace that with:

function importAnyScript(lang,family,script) {

mw.loader.load('//' + lang + '.' + family

		+ '.org/w/index.php?title='
		+ script + '&action=raw&ctype=text/javascript');
  }

In fact, when I copied your global.js, and replaced your importAnyScript() function with my version, it worked.