Better commenting

This commit is contained in:
Timothy Warren 2012-04-26 10:11:15 -04:00
parent b0ca0fc8d9
commit d056f7fac5
5 changed files with 101 additions and 14 deletions

View File

@ -1,4 +1,16 @@
<?php <?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
*/
// --------------------------------------------------------------------------
/* /*
|-------------------------------------------------------------------------- |--------------------------------------------------------------------------

View File

@ -1,4 +1,20 @@
<?php <?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( return array(
/*----- /*-----
Css Css
@ -12,4 +28,5 @@ return array(
'path/to/css/file2.css' 'path/to/css/file2.css'
), ),
*/ */
); );
// End of css_groups.php

View File

@ -1,11 +1,29 @@
<?php <?php
return array( /**
/* * Easy Min
For each group create an array like so *
* Simple minification for better website performance
'my_group' => array( *
'path/to/css/file1.css', * @author Timothy J. Warren
'path/to/css/file2.css' * @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
View File

@ -1,4 +1,17 @@
<?php <?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 //Get config files
require('./config/config.php'); require('./config/config.php');
@ -37,6 +50,8 @@ function compress($buffer) {
return $buffer; return $buffer;
} }
// --------------------------------------------------------------------------
//Creative rewriting //Creative rewriting
$pi = $_SERVER['PATH_INFO']; $pi = $_SERVER['PATH_INFO'];
$pia = explode('/', $pi); $pia = explode('/', $pi);
@ -54,9 +69,12 @@ while($i < $pia_len)
$i = $j + 1; $i = $j + 1;
}; };
// --------------------------------------------------------------------------
$css = ''; $css = '';
$modified = array(); $modified = array();
// Get all the css files, and concatenate them together
if(isset($groups[$_GET['g']])) if(isset($groups[$_GET['g']]))
{ {
foreach($groups[$_GET['g']] as $file) 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); $modified[] = filemtime($this_file);
//Get the latest modified date //Get the latest modified date
rsort($modified); rsort($modified);
$last_modified = $modified[0]; $last_modified = $modified[0];
if(!isset($_GET['debug'])) // If not in debug mode, minify the css
if( ! isset($_GET['debug']))
{ {
$css = compress($css); $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); $css = strtr($css, $path_from, $path_to);
$requested_time=(isset($_SERVER['HTTP_IF_MODIFIED_SINCE'])) $requested_time=(isset($_SERVER['HTTP_IF_MODIFIED_SINCE']))
? strtotime($_SERVER['HTTP_IF_MODIFIED_SINCE']) ? strtotime($_SERVER['HTTP_IF_MODIFIED_SINCE'])
: time(); : time();
// Send 304 when not modified for faster response
if($last_modified === $requested_time) if($last_modified === $requested_time)
{ {
header("HTTP/1.1 304 Not Modified"); 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; echo $css;
ob_end_flush(); ob_end_flush();
//End of css.php //End of css.php

18
js.php
View File

@ -1,4 +1,17 @@
<?php <?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 //Get config files
require('./config/config.php'); require('./config/config.php');
@ -73,6 +86,8 @@ while($i < $pia_len)
$i = $j + 1; $i = $j + 1;
}; };
// --------------------------------------------------------------------------
$js = ''; $js = '';
$modified = array(); $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."); 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'])) else if(isset($_GET['debug']))
{ {
$js = get_files(); $js = get_files();
} }
// Otherwise, send the cached file
else else
{ {
$js = file_get_contents($cache_file); $js = file_get_contents($cache_file);
@ -153,6 +170,7 @@ else
//making file size smaller and transfer rate quicker //making file size smaller and transfer rate quicker
ob_start("ob_gzhandler"); ob_start("ob_gzhandler");
// Set important caching headers
header("Content-Type: application/javascript; charset=utf8"); header("Content-Type: application/javascript; charset=utf8");
header("Cache-control: public, max-age=691200, must-revalidate"); header("Cache-control: public, max-age=691200, must-revalidate");
header("Last-Modified: ".gmdate('D, d M Y H:i:s', $last_modified)." GMT"); header("Last-Modified: ".gmdate('D, d M Y H:i:s', $last_modified)." GMT");