From 2b6eb60ce53cd71af8b6ef1d860ef6d3b3a684a2 Mon Sep 17 00:00:00 2001 From: "Ori.livneh" Date: Sat, 21 Mar 2015 05:14:02 +0000 Subject: [PATCH] Revert "Optimize order of styles and scripts" The patch did not improve performance. I'd like to think that the increased control over when inline scripts are executed makes the patch worthwhile regardless, but that is post hoc justification and possibly a bit of personal ego. Krinkle agrees that we may use some of the ideas in this patch in the future but he thinks we're better off not heading down this path before we have a better sense of where we're going, and I trust his judgment. This reverts commit e86e5f8460b922cadac231142a495f3259c67b43. Change-Id: I151f74a41dd664b5a0aa5cfd99fcc95e2686a1e6 --- includes/EditPage.php | 2 +- includes/OutputPage.php | 88 ++++++++++--------- includes/debug/MWDebug.php | 6 +- includes/resourceloader/ResourceLoader.php | 15 ---- .../ResourceLoaderStartUpModule.php | 11 +-- includes/skins/Skin.php | 4 +- includes/specials/SpecialJavaScriptTest.php | 16 ++-- tests/phpunit/includes/OutputPageTest.php | 52 +++++------ 8 files changed, 84 insertions(+), 110 deletions(-) diff --git a/includes/EditPage.php b/includes/EditPage.php index fe96f9a1cf..6bdb85c3b1 100644 --- a/includes/EditPage.php +++ b/includes/EditPage.php @@ -3708,7 +3708,7 @@ HTML } $script .= '});'; - $wgOut->addScript( ResourceLoader::makeInlineScript( $script ) ); + $wgOut->addScript( Html::inlineScript( ResourceLoader::makeLoaderConditionalScript( $script ) ) ); $toolbar = '
'; diff --git a/includes/OutputPage.php b/includes/OutputPage.php index 5ad33fad0f..edeae0d139 100644 --- a/includes/OutputPage.php +++ b/includes/OutputPage.php @@ -2674,12 +2674,10 @@ class OutputPage extends ContextSource { $ret .= $item . "\n"; } - $ret .= $this->getInlineHeadScript(); - // No newline after buildCssLinks since makeResourceLoaderLink did that already $ret .= $this->buildCssLinks(); - $ret .= $this->getHeadScripts(); + $ret .= $this->getHeadScripts() . "\n"; foreach ( $this->mHeadItems as $item ) { $ret .= $item . "\n"; @@ -2856,8 +2854,10 @@ class OutputPage extends ContextSource { $resourceLoader->makeModuleResponse( $context, $grpModules ) ); } else { - $links['html'] .= ResourceLoader::makeInlineScript( - $resourceLoader->makeModuleResponse( $context, $grpModules ) + $links['html'] .= Html::inlineScript( + ResourceLoader::makeLoaderConditionalScript( + $resourceLoader->makeModuleResponse( $context, $grpModules ) + ) ); } $links['html'] .= "\n"; @@ -2896,8 +2896,10 @@ class OutputPage extends ContextSource { if ( $only === ResourceLoaderModule::TYPE_STYLES ) { $link = Html::linkedStyle( $url ); } elseif ( $loadCall ) { - $link = ResourceLoader::makeInlineScript( - Xml::encodeJsCall( 'mw.loader.load', array( $url, 'text/javascript', true ) ) + $link = Html::inlineScript( + ResourceLoader::makeLoaderConditionalScript( + Xml::encodeJsCall( 'mw.loader.load', array( $url, 'text/javascript', true ) ) + ) ); } else { $link = Html::linkedScript( $url ); @@ -2906,8 +2908,10 @@ class OutputPage extends ContextSource { // browsers not supported by the startup module would unconditionally // execute this module. Otherwise users will get "ReferenceError: mw is // undefined" or "jQuery is undefined" from e.g. a "site" module. - $link = ResourceLoader::makeInlineScript( - Xml::encodeJsCall( 'document.write', array( $link ) ) + $link = Html::inlineScript( + ResourceLoader::makeLoaderConditionalScript( + Xml::encodeJsCall( 'document.write', array( $link ) ) + ) ); } @@ -2951,44 +2955,16 @@ class OutputPage extends ContextSource { } if ( count( $states ) ) { - $html = ResourceLoader::makeInlineScript( - ResourceLoader::makeLoaderStateScript( $states ) + $html = Html::inlineScript( + ResourceLoader::makeLoaderConditionalScript( + ResourceLoader::makeLoaderStateScript( $states ) + ) ) . "\n" . $html; } return $html; } - /** - * Get + ' ' ), array( // Don't condition wrap raw modules (like the startup module) array( 'test.raw', ResourceLoaderModule::TYPE_SCRIPTS ), - ' + ' ' ), // Load module styles only // This also tests the order the modules are put into the url array( array( array( 'test.baz', 'test.foo', 'test.bar' ), ResourceLoaderModule::TYPE_STYLES ), - ' + ' ' ), // Load private module (only=scripts) array( array( 'test.quux', ResourceLoaderModule::TYPE_SCRIPTS ), - ' + ' ' ), // Load private module (combined) array( array( 'test.quux', ResourceLoaderModule::TYPE_COMBINED ), - ' + ' ' ), // Load module script with ESI array( array( 'test.foo', ResourceLoaderModule::TYPE_SCRIPTS, true ), - ' + ' ' ), // Load module styles with ESI array( array( 'test.foo', ResourceLoaderModule::TYPE_STYLES, true ), - ' + ' ', ), // Load no modules @@ -201,22 +197,18 @@ class OutputPageTest extends MediaWikiTestCase { // noscript group array( array( 'test.noscript', ResourceLoaderModule::TYPE_STYLES ), - ' + ' ' ), // Load two modules in separate groups array( array( array( 'test.group.foo', 'test.group.bar' ), ResourceLoaderModule::TYPE_COMBINED ), - ' - + ' + ' ), ); -- 2.20.1