Reduce output size of Skin::makeVariablesScript() for the head variables.
authorBrion Vibber <brion@users.mediawiki.org>
Sat, 22 Aug 2009 19:55:28 +0000 (19:55 +0000)
committerBrion Vibber <brion@users.mediawiki.org>
Sat, 22 Aug 2009 19:55:28 +0000 (19:55 +0000)
Drops a lot of unnecessary whitespace (but keeps newlines for legibility) and puts multiple defs into a single 'var' statement.
Reduces the head vars script from 1485 bytes to 1201 (nearly 20% savings), though this is of course reduced with gzipping (27 bytes, 4%). Cutting those bytes out of *every dang request* doesn't hurt though. :)

includes/Skin.php

index 8d32a04..7f1fd14 100644 (file)
@@ -333,13 +333,17 @@ class Skin extends Linker {
        }
 
        static function makeVariablesScript( $data ) {
-               $r = array();
-               foreach ( $data as $name => $value ) {
-                       $encValue = Xml::encodeJsVar( $value );
-                       $r[] = "var $name = $encValue;";
+               if( $data ) {
+                       $r = array();
+                       foreach ( $data as $name => $value ) {
+                               $encValue = Xml::encodeJsVar( $value );
+                               $r[] = "$name=$encValue";
+                       }
+                       $js = 'var ' . implode( ",\n", $r ) . ';';
+                       return Html::inlineScript( "\n$js\n" );
+               } else {
+                       return '';
                }
-               return Html::inlineScript( "\n\t\t" . implode( "\n\t\t", $r ) .
-                       "\n\t\t" );
        }
 
        /**