diff options
| author | wei <> | 2006-01-15 11:04:00 +0000 | 
|---|---|---|
| committer | wei <> | 2006-01-15 11:04:00 +0000 | 
| commit | abc5bbd9c771dcecfa41ba3590cce1c1ef190cdd (patch) | |
| tree | 45884a9f15efb190144165d50f79bab6fa914494 /framework/Web/Javascripts/js/clientscripts.php | |
| parent | 5af330b442f15be0f0535a9e3c053b8e6eb5a202 (diff) | |
Diffstat (limited to 'framework/Web/Javascripts/js/clientscripts.php')
| -rw-r--r-- | framework/Web/Javascripts/js/clientscripts.php | 53 | 
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  | 
