From: Roan Kattouw Date: Fri, 24 Sep 2010 20:01:52 +0000 (+0000) Subject: Support ESI in the resource loader. Only used for the startup module for now, we... X-Git-Tag: 1.31.0-rc.0~34805 X-Git-Url: http://git.cyclocoop.org/%24image?a=commitdiff_plain;h=86a817552ef6be0deb560e04af9aa7ef6af31fb2;p=lhc%2Fweb%2Fwiklou.git Support ESI in the resource loader. Only used for the startup module for now, we'll have to think our ESI strategy through before expanding on that --- diff --git a/includes/DefaultSettings.php b/includes/DefaultSettings.php index 74015ae0aa..c3bb2c75d7 100644 --- a/includes/DefaultSettings.php +++ b/includes/DefaultSettings.php @@ -1666,6 +1666,13 @@ $wgResourceLoaderMaxage = array( */ $wgResourceLoaderDebug = false; +/** + * Enable embedding of certain resources using Edge Side Includes. This will + * improve performance but only works if there is something in front of the + * web server (e..g a Squid or Varnish server) configured to process the ESI. + */ +$wgResourceLoaderUseESI = false; + /** * Enable data URL embedding (experimental). This variable is very temporary and * will be removed once we get this feature stable. diff --git a/includes/OutputPage.php b/includes/OutputPage.php index 5334ec34ef..401ec50516 100644 --- a/includes/OutputPage.php +++ b/includes/OutputPage.php @@ -2280,8 +2280,9 @@ class OutputPage { return $ret; } - static function makeResourceLoaderLink( $skin, $modules, $only ) { - global $wgUser, $wgLang, $wgRequest, $wgLoadScript, $wgResourceLoaderDebug; + // TODO: Document + static function makeResourceLoaderLink( $skin, $modules, $only, $useESI = false ) { + global $wgUser, $wgLang, $wgRequest, $wgLoadScript, $wgResourceLoaderDebug, $wgResourceLoaderUseESI; // TODO: Should this be a static function of ResourceLoader instead? // TODO: Divide off modules starting with "user", and add the user parameter to them $query = array( @@ -2327,11 +2328,22 @@ class OutputPage { } // Make queries uniform in order ksort( $query ); - // Automatically select style/script elements - if ( $only === 'styles' ) { - $links .= Html::linkedStyle( wfAppendQuery( $wgLoadScript, $query ) ) . "\n"; + + $url = wfAppendQuery( $wgLoadScript, $query ); + if ( $useESI && $wgResourceLoaderUseESI ) { + $esi = Xml::element( 'esi:include', array( 'src' => $url ) ); + if ( $only == 'styles' ) { + $links .= Html::inlineStyle( $esi ); + } else { + $links .= Html::inlineScript( $esi ); + } } else { - $links .= Html::linkedScript( wfAppendQuery( $wgLoadScript, $query ) ) . "\n"; + // Automatically select style/script elements + if ( $only === 'styles' ) { + $links .= Html::linkedStyle( wfAppendQuery( $wgLoadScript, $query ) ) . "\n"; + } else { + $links .= Html::linkedScript( wfAppendQuery( $wgLoadScript, $query ) ) . "\n"; + } } } return $links; @@ -2348,8 +2360,8 @@ class OutputPage { function getHeadScripts( Skin $sk ) { global $wgUser, $wgRequest, $wgUseSiteJs, $wgResourceLoaderDebug; - // Statup - this will immediately load jquery and mediawiki modules - $scripts = self::makeResourceLoaderLink( $sk, 'startup', 'scripts' ); + // Startup - this will immediately load jquery and mediawiki modules + $scripts = self::makeResourceLoaderLink( $sk, 'startup', 'scripts', true ); // Configuration -- This could be merged together with the load and go, but makeGlobalVariablesScript returns a // whole script tag -- grumble grumble...