jenkins-bot has submitted this change and it was merged.
Change subject: Optimize the order of styles and scripts in <head>
......................................................................
Optimize the order of styles and scripts in <head>
Emit styles and scripts in the following order:
* Inline <script>...</script> tags.
* External stylesheets.
* External script tags.
I have attempted this before in I98d383a6, and subsequently reverted (in
I151f74a41) when it failed to show a performance improvement. Our ability
to measure performance were substantially poorer then, so I would like to
give this another try and see if it makes a dent in first render times.
Change-Id: I5e6c79c7041aa77bcdc6130e91e77aa538334c42
---
M includes/OutputPage.php
1 file changed, 33 insertions(+), 13 deletions(-)
Approvals:
Aaron Schulz: Looks good to me, approved
jenkins-bot: Verified
diff --git a/includes/OutputPage.php b/includes/OutputPage.php
index d694e58..f90f91b 100644
--- a/includes/OutputPage.php
+++ b/includes/OutputPage.php
@@ -2702,14 +2702,13 @@
}
$ret .= Html::element( 'title', null, $this->getHTMLTitle() ) .
"\n";
-
+ $ret .= $this->getInlineHeadScripts() . "\n";
$ret .= $this->buildCssLinks() . "\n";
+ $ret .= $this->getExternalHeadScripts() . "\n";
foreach ( $this->getHeadLinksArray() as $item ) {
$ret .= $item . "\n";
}
-
- $ret .= $this->getHeadScripts() . "\n";
foreach ( $this->mHeadItems as $item ) {
$ret .= $item . "\n";
@@ -2879,7 +2878,7 @@
// Inline private modules. These can't be
loaded through load.php for security
// reasons, see bug 34907. Note that these
modules should be loaded from
- // getHeadScripts() before the first loader
call. Otherwise other modules can't
+ // getExternalHeadScripts() before the first
loader call. Otherwise other modules can't
// properly use them as dependencies (bug 30914)
if ( $group === 'private' ) {
if ( $only ==
ResourceLoaderModule::TYPE_STYLES ) {
@@ -2982,6 +2981,34 @@
* @return string HTML fragment
*/
function getHeadScripts() {
+ return $this->getInlineHeadScripts() . "\n" .
$this->getExternalHeadScripts();
+ }
+
+ /**
+ * <script src="..."> tags for "<head>". This is the startup module
+ * and other modules marked with position 'top'.
+ *
+ * @return string HTML fragment
+ */
+ function getExternalHeadScripts() {
+ $links = array();
+
+ // Startup - this provides the client with the module manifest
and loads jquery and mediawiki base modules
+ $links[] = $this->makeResourceLoaderLink( 'startup',
ResourceLoaderModule::TYPE_SCRIPTS );
+
+ if ( $this->getConfig()->get(
'ResourceLoaderExperimentalAsyncLoading' ) ) {
+ $links[] = $this->getScriptsForBottomQueue();
+ }
+
+ return self::getHtmlFromLoaderLinks( $links );
+ }
+
+ /**
+ * <script>...</script> tags to put in "<head>".
+ *
+ * @return string HTML fragment
+ */
+ function getInlineHeadScripts() {
$links = array();
// Client profile classes for <html>. Allows for easy
hiding/showing of UI components.
@@ -2994,9 +3021,6 @@
'document.documentElement.className =
document.documentElement.className'
. '.replace( /(^|\s)client-nojs(\s|$)/, "$1client-js$2"
);'
);
-
- // Startup - this provides the client with the module manifest
and loads jquery and mediawiki base modules
- $links[] = $this->makeResourceLoaderLink( 'startup',
ResourceLoaderModule::TYPE_SCRIPTS );
// Load config before anything else
$links[] = ResourceLoader::makeInlineScript(
@@ -3026,10 +3050,6 @@
ResourceLoaderModule::TYPE_SCRIPTS
);
- if ( $this->getConfig()->get(
'ResourceLoaderExperimentalAsyncLoading' ) ) {
- $links[] = $this->getScriptsForBottomQueue();
- }
-
return self::getHtmlFromLoaderLinks( $links );
}
@@ -3041,7 +3061,7 @@
* and user JS.
*
* @param bool $unused Previously used to let this method change its
output based
- * on whether it was called by getHeadScripts() or getBottomScripts().
+ * on whether it was called by getExternalHeadScripts() or
getBottomScripts().
* @return string
*/
function getScriptsForBottomQueue( $unused = null ) {
@@ -3123,7 +3143,7 @@
$this->getSkin()->setupSkinUserCss( $this );
if ( $this->getConfig()->get(
'ResourceLoaderExperimentalAsyncLoading' ) ) {
- // Already handled by getHeadScripts()
+ // Already handled by getExternalHeadScripts()
return '';
}
return $this->getScriptsForBottomQueue();
--
To view, visit https://gerrit.wikimedia.org/r/231434
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I5e6c79c7041aa77bcdc6130e91e77aa538334c42
Gerrit-PatchSet: 4
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Ori.livneh <[email protected]>
Gerrit-Reviewer: Aaron Schulz <[email protected]>
Gerrit-Reviewer: Daniel Friesen <[email protected]>
Gerrit-Reviewer: Ori.livneh <[email protected]>
Gerrit-Reviewer: jenkins-bot <>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits