summaryrefslogtreecommitdiff
path: root/framework/Web/Javascripts/js/clientscripts.php
diff options
context:
space:
mode:
Diffstat (limited to 'framework/Web/Javascripts/js/clientscripts.php')
-rw-r--r--framework/Web/Javascripts/js/clientscripts.php53
1 files changed, 53 insertions, 0 deletions
diff --git a/framework/Web/Javascripts/js/clientscripts.php b/framework/Web/Javascripts/js/clientscripts.php
new file mode 100644
index 00000000..2bc206da
--- /dev/null
+++ b/framework/Web/Javascripts/js/clientscripts.php
@@ -0,0 +1,53 @@
+<?php
+/**
+ * This file compresses the javascript files using GZip
+ *
+ * Todo:
+ * - Add local file cache for the GZip:ed version.
+ */
+
+if(isset($_GET['nocache']))
+ $expiresOffset = -10000; //no cache
+else
+ $expiresOffset = 3600 * 24 * 10; // 10 days util client cache expires
+
+// Get data to load
+$library = array( 'base', 'dom', 'effects', 'controls', 'logger',
+ 'ajax', 'rico', 'validator', 'datepicker');
+
+$param = isset($_GET['js']) ? $_GET['js'] : '';
+
+//check for proper matching parameters, otherwise exit;
+if(preg_match('/(\w)+(,\w+)*/', $param)) $js = explode(',', $param); else exit();
+foreach($js as $lib) if(!in_array($lib, $library)) exit();
+
+// Only gzip the contents if clients and server support it
+if (isset($_SERVER['HTTP_ACCEPT_ENCODING']))
+ $encodings = explode(',', strtolower($_SERVER['HTTP_ACCEPT_ENCODING']));
+else
+ $encodings = array();
+
+// Check for gzip header or northon internet securities
+if ((in_array('gzip', $encodings) || isset($_SERVER['---------------']))
+ && function_exists('ob_gzhandler') && !ini_get('zlib.output_compression'))
+ ob_start("ob_gzhandler");
+
+// Output rest of headers
+header('Content-type: text/javascript; charset: UTF-8');
+// header("Cache-Control: must-revalidate");
+header('Vary: Accept-Encoding'); // Handle proxies
+header('Expires: ' . @gmdate('D, d M Y H:i:s', @time() + $expiresOffset) . ' GMT');
+
+foreach($js as $lib)
+{
+ $file = realpath($lib.'.js');
+ if(is_file($file))
+ echo file_get_contents($file);
+ else //log missings files to console logger
+ {
+ echo 'setTimeout(function(){ if(Logger) Logger.error("Missing file", "'.$lib.'.js"); }, 1000);';
+ error_log("Unable to find asset file {$lib}.js");
+ }
+}
+
+?> \ No newline at end of file