summaryrefslogtreecommitdiff
path: root/javascript/jscompressor.php
blob: 0c2e84a95780729afdfd3190caf8548c4cc581e8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
<?php
/**
 * $Header$
 * adapted from tinyMCE gzipper
 */

// initial setup
require_once( "../../kernel/includes/setup_inc.php" );

// General options
$expiresOffset = 3600 * 24 * 10;		// 10 days util client cache expires
$jsfile = ( !empty( $_REQUEST['jsfile'] ) ? UTIL_PKG_PATH."javascript/".$_REQUEST['jsfile'] : ( !empty( $_REQUEST['jspath'] ) ? $_REQUEST['jspath'] : NULL ) );

// Only gzip the contents if clients and server support it
$encodings = array();
if( isset( $_SERVER['HTTP_ACCEPT_ENCODING'] ) ) {
	$encodings = explode(',', strtolower( $_SERVER['HTTP_ACCEPT_ENCODING'] ) );
}

// Check for gzip header or norton 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" );

// get the file contents
if( !empty( $jsfile ) && is_readable( $jsfile ) ) {
	echo file_get_contents( $jsfile );
}
while( @ob_end_flush() );
?>