Anomie has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/61057


Change subject: (bug 47457) Add mw.loader.forceAsync flag
......................................................................

(bug 47457) Add mw.loader.forceAsync flag

It is possible for an async-loaded script to run in between the time at
which document.write becomes unsafe and the time $.isReady gets set in
the DOMContentLoaded method. And if this async-loaded script happens to
call mw.loader.using, or mw.loader.load with async false, or anything
else that winds up in the addScript function in
resources/mediawiki/mediawiki.js with async not true, boom.

It has been said that the only real use for the synchronous loading is
in the top-loading queue, so let's just add a flag to force async
loading and set it at the end of the top-loading queue.

At some point, though, things should really be cleaned up so async
loading is the default and sync is only used if explicitly specified.
But I'll leave that to someone who knows more about the various things
that might be depending on the current semi-default synchronous loading.

Bug: 47457
Change-Id: Ic3d0c937268d0943d2f770f3ca18bcf4e1eed346
---
M includes/OutputPage.php
M resources/mediawiki/mediawiki.js
2 files changed, 8 insertions(+), 1 deletion(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core 
refs/changes/57/61057/1

diff --git a/includes/OutputPage.php b/includes/OutputPage.php
index bf3c084..748ff5c 100644
--- a/includes/OutputPage.php
+++ b/includes/OutputPage.php
@@ -2821,6 +2821,12 @@
                        $scripts .= $this->getScriptsForBottomQueue( true );
                }
 
+               $scripts .= Html::inlineScript(
+                       ResourceLoader::makeLoaderConditionalScript(
+                               'mw.loader.forceAsync = true;'
+                       )
+               );
+
                return $scripts;
        }
 
diff --git a/resources/mediawiki/mediawiki.js b/resources/mediawiki/mediawiki.js
index 6c7e697..674ef74 100644
--- a/resources/mediawiki/mediawiki.js
+++ b/resources/mediawiki/mediawiki.js
@@ -820,7 +820,7 @@
 
                                // Using isReady directly instead of storing it 
locally from
                                // a $.fn.ready callback (bug 31895).
-                               if ( $.isReady || async ) {
+                               if ( mw.loader.forceAsync || $.isReady || async 
) {
                                        // Can't use jQuery.getScript because 
that only uses <script> for cross-domain,
                                        // it uses XHR and eval for same-domain 
scripts, which we don't want because it
                                        // messes up line numbers.
@@ -1145,6 +1145,7 @@
 
                        /* Public Methods */
                        return {
+                               forceAsync: false,
                                addStyleTag: addStyleTag,
 
                                /**

-- 
To view, visit https://gerrit.wikimedia.org/r/61057
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ic3d0c937268d0943d2f770f3ca18bcf4e1eed346
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Anomie <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to