Krinkle has uploaded a new change for review.
https://gerrit.wikimedia.org/r/271553
Change subject: OutputPage: Minor optimisation for size of JS/CSS in <head>
......................................................................
OutputPage: Minor optimisation for size of JS/CSS in <head>
This does a simple pass on various places where we try too hard
to make pretty output.
This change is less concerned about the HTML as whole (which requires
more rigorous changes to make a difference), and there's some controversy
around keeping overall skin HTML more readable.
Rather, this focusses on the first chunk of the HTML. With the purpose to try
and deliver it all in the first 14k of the response to improve above-the-fold
start render times.
* Remove trailing space in self-closing tag.
This exists because $wgWellFormedXml is on by default.
* Remove various line breaks between scripts and within script contents.
* Change FILTER_NOMIN to mean no-cache, rather than no-minify.
Which is what it was designed for. Follows-up ca30efa. Ensure the
instruction survives by adding it back afterward.
* For now, preserving the line breaks between individual meta and
link items in the <head>.
Bug: T127328
Change-Id: I85a5a59fd0955c1a112e8b24b933f0d9e983a156
---
M includes/Html.php
M includes/OutputPage.php
M includes/resourceloader/ResourceLoader.php
M includes/resourceloader/ResourceLoaderUserTokensModule.php
M tests/phpunit/includes/HtmlTest.php
M tests/phpunit/includes/OutputPageTest.php
6 files changed, 30 insertions(+), 31 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core
refs/changes/53/271553/1
diff --git a/includes/Html.php b/includes/Html.php
index 3b36039..890beb0 100644
--- a/includes/Html.php
+++ b/includes/Html.php
@@ -216,7 +216,7 @@
if ( in_array( $element, self::$voidElements ) ) {
if ( $wgWellFormedXml ) {
// Silly XML.
- return substr( $start, 0, -1 ) . ' />';
+ return substr( $start, 0, -1 ) . '/>';
}
return $start;
} else {
diff --git a/includes/OutputPage.php b/includes/OutputPage.php
index 2570cfb..b8bbdac 100644
--- a/includes/OutputPage.php
+++ b/includes/OutputPage.php
@@ -460,7 +460,7 @@
* @param string $script Raw HTML
*/
function addScript( $script ) {
- $this->mScripts .= $script . "\n";
+ $this->mScripts .= $script;
}
/**
@@ -516,7 +516,7 @@
* @param string $script JavaScript text, no "<script>" tags
*/
public function addInlineScript( $script ) {
- $this->mScripts .= Html::inlineScript( "\n$script\n" ) . "\n";
+ $this->mScripts .= Html::inlineScript( $script );
}
/**
@@ -2989,7 +2989,7 @@
* @return string HTML fragment
*/
function getHeadScripts() {
- return $this->getInlineHeadScripts() . "\n" .
$this->getExternalHeadScripts();
+ return $this->getInlineHeadScripts() .
$this->getExternalHeadScripts();
}
/**
@@ -3671,7 +3671,7 @@
# If wanted, and the interface is right-to-left, flip
the CSS
$style_css = CSSJanus::transform( $style_css, true,
false );
}
- $this->mInlineStyles .= Html::inlineStyle( $style_css ) . "\n";
+ $this->mInlineStyles .= Html::inlineStyle( $style_css );
}
/**
@@ -3723,7 +3723,7 @@
if ( $this->getLanguage()->getDir() !==
$wgContLang->getDir() ) {
$previewedCSS = CSSJanus::transform(
$previewedCSS, true, false );
}
- $otherTags[] = Html::inlineStyle( $previewedCSS ) .
"\n";
+ $otherTags[] = Html::inlineStyle( $previewedCSS );
} else {
// Load the user styles normally
$moduleStyles[] = 'user';
@@ -3762,7 +3762,7 @@
ResourceLoaderModule::TYPE_STYLES
);
// Add normal styles added through addStyle()/addInlineStyle()
here
- $links[] = implode( "\n", $this->buildCssLinksArray() ) .
$this->mInlineStyles;
+ $links[] = implode( '', $this->buildCssLinksArray() ) .
$this->mInlineStyles;
// Add marker tag to mark the place where the client-side
// loader should inject dynamic styles
// We use a <meta> tag with a made-up name for this because
that's valid HTML
diff --git a/includes/resourceloader/ResourceLoader.php
b/includes/resourceloader/ResourceLoader.php
index c689979..05c7b21 100644
--- a/includes/resourceloader/ResourceLoader.php
+++ b/includes/resourceloader/ResourceLoader.php
@@ -87,8 +87,8 @@
*/
private $logger;
- /** @var string JavaScript / CSS pragma to disable minification. **/
- const FILTER_NOMIN = ' /* @nomin */ ';
+ /** @var string JavaScript / CSS pragma to disable minification cache.
**/
+ const FILTER_NOCACHE = '/*@nocache*/';
/**
* Load information stored in the database about modules.
@@ -173,8 +173,8 @@
* @return string Filtered data, or a comment containing an error
message
*/
public static function filter( $filter, $data, array $options = [] ) {
- if ( strpos( $data, ResourceLoader::FILTER_NOMIN ) !== false ) {
- return $data;
+ if ( strpos( $data, ResourceLoader::FILTER_NOCACHE ) !== false
) {
+ return self::applyFilter( $filter, $data ) .
ResourceLoader::FILTER_NOCACHE;
}
if ( isset( $options['cache'] ) && $options['cache'] === false
) {
@@ -1362,8 +1362,8 @@
* @return string
*/
public static function makeLoaderConditionalScript( $script ) {
- return "(window.RLQ = window.RLQ || []).push(function () {\n" .
- trim( $script ) . "\n} );";
+ return '(window.RLQ=window.RLQ||[]).push(function(){' .
+ trim( $script ) . '});';
}
/**
@@ -1379,8 +1379,8 @@
$js = self::makeLoaderConditionalScript( $script );
return new WrappedString(
Html::inlineScript( $js ),
- "<script>(window.RLQ = window.RLQ || []).push(function
() {\n",
- "\n} );</script>"
+ '<script>(window.RLQ=window.RLQ||[]).push(function(){',
+ '});</script>'
);
}
@@ -1396,7 +1396,7 @@
'mw.config.set',
[ $configuration ],
ResourceLoader::inDebugMode()
- ) . ResourceLoader::FILTER_NOMIN;
+ ) . ResourceLoader::FILTER_NOCACHE;
}
/**
diff --git a/includes/resourceloader/ResourceLoaderUserTokensModule.php
b/includes/resourceloader/ResourceLoaderUserTokensModule.php
index bf4e8a7..b3f9b75 100644
--- a/includes/resourceloader/ResourceLoaderUserTokensModule.php
+++ b/includes/resourceloader/ResourceLoaderUserTokensModule.php
@@ -54,8 +54,7 @@
/**
* Generate the JavaScript content of this module.
*
- * Add '@nomin' annotation to prevent the module's contents from getting
- * cached (T84960).
+ * Add FILTER_NOCACHE annotation to prevent caching of this script
(T84960).
*
* @param ResourceLoaderContext $context
* @return string
@@ -65,7 +64,7 @@
'mw.user.tokens.set',
[ $this->contextUserTokens( $context ) ],
ResourceLoader::inDebugMode()
- ) . ResourceLoader::FILTER_NOMIN;
+ ) . ResourceLoader::FILTER_NOCACHE;
}
/**
diff --git a/tests/phpunit/includes/HtmlTest.php
b/tests/phpunit/includes/HtmlTest.php
index a18e3c8..9d10e1d 100644
--- a/tests/phpunit/includes/HtmlTest.php
+++ b/tests/phpunit/includes/HtmlTest.php
@@ -66,7 +66,7 @@
$this->setMwGlobals( 'wgWellFormedXml', true );
$this->assertEquals(
- '<img />',
+ '<img/>',
Html::element( 'img', null, '' ),
'Self-closing tag for short-tag elements
(wgWellFormedXml = true)'
);
diff --git a/tests/phpunit/includes/OutputPageTest.php
b/tests/phpunit/includes/OutputPageTest.php
index d404ab8..9bef038 100644
--- a/tests/phpunit/includes/OutputPageTest.php
+++ b/tests/phpunit/includes/OutputPageTest.php
@@ -142,9 +142,9 @@
// Load module script only
array(
array( 'test.foo',
ResourceLoaderModule::TYPE_SCRIPTS ),
- "<script>(window.RLQ = window.RLQ ||
[]).push(function () {\n"
+
"<script>(window.RLQ=window.RLQ||[]).push(function(){"
.
'mw.loader.load("http://127.0.0.1:8080/w/load.php?debug=false\u0026lang=en\u0026modules=test.foo\u0026only=scripts\u0026skin=fallback");'
- . "\n} );</script>"
+ . "});</script>"
),
array(
// Don't condition wrap raw modules (like the
startup module)
@@ -161,17 +161,17 @@
// Load private module (only=scripts)
array(
array( 'test.quux',
ResourceLoaderModule::TYPE_SCRIPTS ),
- "<script>(window.RLQ = window.RLQ ||
[]).push(function () {\n"
- .
"mw.test.baz({token:123});mw.loader.state({\"test.quux\":\"ready\"});\n"
- . "} );</script>"
+
"<script>(window.RLQ=window.RLQ||[]).push(function(){"
+ .
"mw.test.baz({token:123});mw.loader.state({\"test.quux\":\"ready\"});"
+ . "});</script>"
),
// Load private module (combined)
array(
array( 'test.quux',
ResourceLoaderModule::TYPE_COMBINED ),
- "<script>(window.RLQ = window.RLQ ||
[]).push(function () {\n"
+
"<script>(window.RLQ=window.RLQ||[]).push(function(){"
.
"mw.loader.implement(\"test.quux\",function($,jQuery){"
.
"mw.test.baz({token:123});},{\"css\":[\".mw-icon{transition:none}"
- . "\"]});\n} );</script>"
+ . "\"]});});</script>"
),
// Load no modules
array(
@@ -186,12 +186,12 @@
// Load two modules in separate groups
array(
array( array( 'test.group.foo',
'test.group.bar' ), ResourceLoaderModule::TYPE_COMBINED ),
- "<script>(window.RLQ = window.RLQ ||
[]).push(function () {\n"
+
"<script>(window.RLQ=window.RLQ||[]).push(function(){"
.
'mw.loader.load("http://127.0.0.1:8080/w/load.php?debug=false\u0026lang=en\u0026modules=test.group.bar\u0026skin=fallback");'
- . "\n} );</script>\n"
- . "<script>(window.RLQ = window.RLQ ||
[]).push(function () {\n"
+ . "});</script>\n"
+ .
"<script>(window.RLQ=window.RLQ||[]).push(function(){"
.
'mw.loader.load("http://127.0.0.1:8080/w/load.php?debug=false\u0026lang=en\u0026modules=test.group.foo\u0026skin=fallback");'
- . "\n} );</script>"
+ . "});</script>"
),
);
// @codingStandardsIgnoreEnd
--
To view, visit https://gerrit.wikimedia.org/r/271553
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I85a5a59fd0955c1a112e8b24b933f0d9e983a156
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Krinkle <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits