Better commenting
This commit is contained in:
parent
b0ca0fc8d9
commit
d056f7fac5
@ -1,4 +1,16 @@
|
||||
<?php
|
||||
/**
|
||||
* Easy Min
|
||||
*
|
||||
* Simple minification for better website performance
|
||||
*
|
||||
* @author Timothy J. Warren
|
||||
* @copyright Copyright (c) 2012
|
||||
* @link https://github.com/aviat4ion/Easy-Min
|
||||
* @license http://philsturgeon.co.uk/code/dbad-license
|
||||
*/
|
||||
|
||||
// --------------------------------------------------------------------------
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
|
@ -1,4 +1,20 @@
|
||||
<?php
|
||||
/**
|
||||
* Easy Min
|
||||
*
|
||||
* Simple minification for better website performance
|
||||
*
|
||||
* @author Timothy J. Warren
|
||||
* @copyright Copyright (c) 2012
|
||||
* @link https://github.com/aviat4ion/Easy-Min
|
||||
* @license http://philsturgeon.co.uk/code/dbad-license
|
||||
*/
|
||||
|
||||
// --------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* This is the config array for css files to concatenate and minify
|
||||
*/
|
||||
return array(
|
||||
/*-----
|
||||
Css
|
||||
@ -12,4 +28,5 @@ return array(
|
||||
'path/to/css/file2.css'
|
||||
),
|
||||
*/
|
||||
);
|
||||
);
|
||||
// End of css_groups.php
|
@ -1,11 +1,29 @@
|
||||
<?php
|
||||
return array(
|
||||
/*
|
||||
For each group create an array like so
|
||||
|
||||
'my_group' => array(
|
||||
'path/to/css/file1.css',
|
||||
'path/to/css/file2.css'
|
||||
),
|
||||
*/
|
||||
);
|
||||
/**
|
||||
* Easy Min
|
||||
*
|
||||
* Simple minification for better website performance
|
||||
*
|
||||
* @author Timothy J. Warren
|
||||
* @copyright Copyright (c) 2012
|
||||
* @link https://github.com/aviat4ion/Easy-Min
|
||||
* @license http://philsturgeon.co.uk/code/dbad-license
|
||||
*/
|
||||
|
||||
// --------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* This is the config array for javascript files to concatenate and minify
|
||||
*/
|
||||
return array(
|
||||
/*
|
||||
For each group create an array like so
|
||||
|
||||
'my_group' => array(
|
||||
'path/to/js/file1.js',
|
||||
'path/to/js/file2.js'
|
||||
),
|
||||
*/
|
||||
);
|
||||
|
||||
// End of js_groups.php
|
28
css.php
28
css.php
@ -1,4 +1,17 @@
|
||||
<?php
|
||||
/**
|
||||
* Easy Min
|
||||
*
|
||||
* Simple minification for better website performance
|
||||
*
|
||||
* @author Timothy J. Warren
|
||||
* @copyright Copyright (c) 2012
|
||||
* @link https://github.com/aviat4ion/Easy-Min
|
||||
* @license http://philsturgeon.co.uk/code/dbad-license
|
||||
*/
|
||||
|
||||
// --------------------------------------------------------------------------
|
||||
|
||||
//Get config files
|
||||
require('./config/config.php');
|
||||
|
||||
@ -37,6 +50,8 @@ function compress($buffer) {
|
||||
return $buffer;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------------
|
||||
|
||||
//Creative rewriting
|
||||
$pi = $_SERVER['PATH_INFO'];
|
||||
$pia = explode('/', $pi);
|
||||
@ -54,9 +69,12 @@ while($i < $pia_len)
|
||||
$i = $j + 1;
|
||||
};
|
||||
|
||||
// --------------------------------------------------------------------------
|
||||
|
||||
$css = '';
|
||||
$modified = array();
|
||||
|
||||
// Get all the css files, and concatenate them together
|
||||
if(isset($groups[$_GET['g']]))
|
||||
{
|
||||
foreach($groups[$_GET['g']] as $file)
|
||||
@ -67,24 +85,28 @@ if(isset($groups[$_GET['g']]))
|
||||
}
|
||||
}
|
||||
|
||||
//Add this page too
|
||||
//Add this page for last modified check
|
||||
$modified[] = filemtime($this_file);
|
||||
|
||||
//Get the latest modified date
|
||||
rsort($modified);
|
||||
$last_modified = $modified[0];
|
||||
|
||||
if(!isset($_GET['debug']))
|
||||
// If not in debug mode, minify the css
|
||||
if( ! isset($_GET['debug']))
|
||||
{
|
||||
$css = compress($css);
|
||||
}
|
||||
|
||||
// Correct paths that have changed due to concatenation
|
||||
// based on rules in the config file
|
||||
$css = strtr($css, $path_from, $path_to);
|
||||
|
||||
$requested_time=(isset($_SERVER['HTTP_IF_MODIFIED_SINCE']))
|
||||
? strtotime($_SERVER['HTTP_IF_MODIFIED_SINCE'])
|
||||
: time();
|
||||
|
||||
// Send 304 when not modified for faster response
|
||||
if($last_modified === $requested_time)
|
||||
{
|
||||
header("HTTP/1.1 304 Not Modified");
|
||||
@ -103,4 +125,4 @@ header("Expires: ".gmdate('D, d M Y H:i:s', (filemtime($this_file) + 691200))."
|
||||
echo $css;
|
||||
|
||||
ob_end_flush();
|
||||
//End of css.php
|
||||
//End of css.php
|
18
js.php
18
js.php
@ -1,4 +1,17 @@
|
||||
<?php
|
||||
/**
|
||||
* Easy Min
|
||||
*
|
||||
* Simple minification for better website performance
|
||||
*
|
||||
* @author Timothy J. Warren
|
||||
* @copyright Copyright (c) 2012
|
||||
* @link https://github.com/aviat4ion/Easy-Min
|
||||
* @license http://philsturgeon.co.uk/code/dbad-license
|
||||
*/
|
||||
|
||||
// --------------------------------------------------------------------------
|
||||
|
||||
//Get config files
|
||||
require('./config/config.php');
|
||||
|
||||
@ -73,6 +86,8 @@ while($i < $pia_len)
|
||||
$i = $j + 1;
|
||||
};
|
||||
|
||||
// --------------------------------------------------------------------------
|
||||
|
||||
$js = '';
|
||||
$modified = array();
|
||||
|
||||
@ -138,10 +153,12 @@ if($cache_modified < $last_modified)
|
||||
die("Cache file was not created. Make sure you have the correct folder permissions.");
|
||||
}
|
||||
}
|
||||
// If debug is set, just concatenate
|
||||
else if(isset($_GET['debug']))
|
||||
{
|
||||
$js = get_files();
|
||||
}
|
||||
// Otherwise, send the cached file
|
||||
else
|
||||
{
|
||||
$js = file_get_contents($cache_file);
|
||||
@ -153,6 +170,7 @@ else
|
||||
//making file size smaller and transfer rate quicker
|
||||
ob_start("ob_gzhandler");
|
||||
|
||||
// Set important caching headers
|
||||
header("Content-Type: application/javascript; charset=utf8");
|
||||
header("Cache-control: public, max-age=691200, must-revalidate");
|
||||
header("Last-Modified: ".gmdate('D, d M Y H:i:s', $last_modified)." GMT");
|
||||
|
Loading…
Reference in New Issue
Block a user