Skip to content

Commit

Permalink
Call jQuery.ready() before </body>
Browse files Browse the repository at this point in the history
mw.loader defaults to async=false. Overridden when $.isReady=true
or a mw.loader call sets async=true.

The problem is in calls to mw.loader.load that are not in
the HTML output but occur *before* the DOMContentReady event.

In those cases we want to use async (creating a script tag)
instead of synchronous (document.write) because in Firefox
DOMContentReady is emitted some time after it is no longer safe
to use document.write (bug 47457).

This also optimises the dom ready event cross-browser.

Bug: 34542
Bug: 47457
Change-Id: Ic3d0c937268d0943d2f770f3ca18bcf4e1eed346
  • Loading branch information
Krinkle committed Apr 29, 2013
1 parent 8e7150b commit 0a000d5
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions includes/OutputPage.php
Expand Up @@ -2954,11 +2954,18 @@ function getScriptsForBottomQueue( $inHead ) {
*/
function getBottomScripts() {
global $wgResourceLoaderExperimentalAsyncLoading;

// Optimise jQuery ready event cross-browser.
// This also enforces $.isReady to be true at </body> which fixes the
// mw.loader bug in Firefox with using document.write between </body>
// and the DOMContentReady event (bug 47457).
$html = Html::inlineScript( 'jQuery.ready();' );

if ( !$wgResourceLoaderExperimentalAsyncLoading ) {
return $this->getScriptsForBottomQueue( false );
} else {
return '';
$html .= $this->getScriptsForBottomQueue( false );
}

return $html;
}

/**
Expand Down

0 comments on commit 0a000d5

Please sign in to comment.