Support ESI in the resource loader. Only used for the startup module for now, we...
authorRoan Kattouw <catrope@users.mediawiki.org>
Fri, 24 Sep 2010 20:01:52 +0000 (20:01 +0000)
committerRoan Kattouw <catrope@users.mediawiki.org>
Fri, 24 Sep 2010 20:01:52 +0000 (20:01 +0000)
includes/DefaultSettings.php
includes/OutputPage.php

index 74015ae..c3bb2c7 100644 (file)
@@ -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.
index 5334ec3..401ec50 100644 (file)
@@ -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...