浏览代码

AMBARI-218. Install Combo-Handler On HMC Webserver To Drastically Speed Up Page Load Times

git-svn-id: https://svn.apache.org/repos/asf/incubator/ambari/branches/ambari-186@1339729 13f79535-47bb-0310-9956-ffa450edef68
Ramya Sunil 13 年之前
父节点
当前提交
ddea474efe
共有 3 个文件被更改,包括 62 次插入1 次删除
  1. 3 0
      CHANGES.txt
  2. 7 1
      hmc/html/bootstrapJs.htmli
  3. 52 0
      hmc/yuiCombinator.php

+ 3 - 0
CHANGES.txt

@@ -2,6 +2,9 @@ Ambari Change log
 
 Release 0.x.x - unreleased
 
+  AMBARI-218. Install Combo-Handler On HMC Webserver To Drastically Speed Up
+  Page Load Times (Varun Kapoor via ramya)
+
   AMBARI-259. add nodes to a cluster gives an option for ganglia and dashboard,
   these should be on by default (Vinod via ramya)
 

+ 7 - 1
hmc/html/bootstrapJs.htmli

@@ -18,7 +18,13 @@
     }
   }
 
-  var globalYui = YUI().use( 
+  var globalYuiLoaderOptions = {
+    combine: true,
+    comboBase: '../yuiCombinator.php?',
+    root: 'yui-3.4.1/build/'
+  };
+
+  var globalYui = YUI( globalYuiLoaderOptions ).use( 
     "node", "io", "dump", "json", "panel", "event", "arraysort", 
     "array-extras", "datasource", "datasource-io", "datasource-jsonschema", 
     "datasource-polling", "stylesheet", "dd-drop", "dd-constrain",

+ 52 - 0
hmc/yuiCombinator.php

@@ -0,0 +1,52 @@
+<?php
+
+function deduceContentType ($fileToLoad)
+{
+  $contentType = '';
+
+  $fileExtension = pathinfo($fileToLoad, PATHINFO_EXTENSION);
+
+  if ($fileExtension == 'css')
+  {
+    $contentType = 'text/css';
+  }
+  elseif ($fileExtension == 'js' )
+  {
+    $contentType = 'application/js';
+  }
+
+  return $contentType;
+}
+
+/* main() */
+$filesToLoad = explode('&', $_SERVER['QUERY_STRING']);
+
+$contentType = '';
+$responseBody = '';
+
+foreach ($filesToLoad as $fileToLoad) 
+{
+  /* Assumes a request has only homogenous file types, which holds true for 
+   * the combined requests YUI makes. 
+   */
+  if (empty($contentType))
+  {
+    $contentType = deduceContentType($fileToLoad);
+  }
+
+  $fileContents = file_get_contents('./' . $fileToLoad);
+
+  if ($fileContents)
+  {
+    $responseBody .= $fileContents;
+  }
+}
+
+header('Content-type: ' . $contentType);
+/* TODO XXX Add appropriate Cache-Control/Age/Last-Modified/Expires headers 
+ * here to be super-efficient. 
+ */
+
+echo $responseBody;
+
+?>