From e1cb8bb7b4ba0425d8af44197d9ea97d35751423 Mon Sep 17 00:00:00 2001 From: Brion Vibber Date: Sat, 22 Aug 2009 19:55:28 +0000 Subject: [PATCH] Reduce output size of Skin::makeVariablesScript() for the head variables. 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 | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/includes/Skin.php b/includes/Skin.php index 8d32a04dd7..7f1fd14c0c 100644 --- a/includes/Skin.php +++ b/includes/Skin.php @@ -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" ); } /** -- 2.20.1