From 0a000d5cf4f915f8b5cdb5e2b25674200952f4ce Mon Sep 17 00:00:00 2001 From: Timo Tijhof Date: Thu, 25 Apr 2013 10:12:07 +0200 Subject: [PATCH] Call jQuery.ready() before 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 --- includes/OutputPage.php | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/includes/OutputPage.php b/includes/OutputPage.php index 65800dd49c..2f1f62ee96 100644 --- a/includes/OutputPage.php +++ b/includes/OutputPage.php @@ -2954,11 +2954,18 @@ $templates */ function getBottomScripts() { global $wgResourceLoaderExperimentalAsyncLoading; + + // Optimise jQuery ready event cross-browser. + // This also enforces $.isReady to be true at which fixes the + // mw.loader bug in Firefox with using document.write between + // 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; } /** -- 2.20.1