1
0
mirror of https://github.com/mrclay/minify.git synced 2025-08-10 16:14:18 +02:00

+ README.txt

min/config.php: removed $minifyAllowBase option and reorganized file
min/index.php: added option to send far-off expires if "&\d" matches query string
This commit is contained in:
Steve Clay
2008-08-19 21:01:05 +00:00
parent 51adb91399
commit 62d7c83d80
4 changed files with 132 additions and 30 deletions

81
min/README.txt Normal file
View File

@@ -0,0 +1,81 @@
The files in this directory represent the default Minify setup designed to ease
integration with your site. Out-of-the-box, Minify can combine and minify files
and serve them with HTTP compression and cache headers.
RECOMMENDED
It's recommended to edit config.php to set $minifyCachePath to a writeable
directory on your system. This will slightly improve the performance of each
request.
MINIFYING A SINGLE FILE
Let's say you want to serve this file:
http://example.com/wp-content/themes/default/default.css
Here's the "Minify URL" for this file:
http://example.com/min/?f=wp-content/themes/default/default.css
In other words, the "f" argument is set to the file path from root without the
initial "/". As CSS files may contain relative URIs, Minify will automatically
"fix" these by rewriting them as root relative.
COMBINING MULTIPLE FILES IN ONE DOWNLOAD
Separate the file paths given to "f" with commas.
Let's say you have CSS files at these URLs:
http://example.com/scripts/jquery-1.2.6.js
http://example.com/scripts/site.js
You can combine these files through Minify by requesting this URL:
http://example.com/min/?f=scripts/jquery-1.2.6.js,scripts/site.js
SIMPLIFYING URLS WITH A BASE PATH
If you're combining files that share the same ancestor directory, you can use
the "b" argument to set the base directory for the "f" argument. Do not include
the leading or trailing "/" characters.
E.g., the following URLs will serve the exact same content:
http://example.com/min/?f=scripts/jquery-1.2.6.js,scripts/site.js
http://example.com/min/?b=scripts&f=jquery-1.2.6.js,site.js
USING THESE URLS IN HTML
In (X)HTML files, make sure to replace any "&" characters with "&".
SPECIFYING ALLOWED DIRECTORIES
By default, Minify will serve any *.css/*.js files within the DOCUMENT_ROOT. If
you'd prefer to limit Minify's access to certain directories, set the
$minifyAllowDirs array in config.php. E.g. to limit to the /js and
/themes/default directories, use:
$minifyAllowDirs = array('//js', '//themes/default');
FASTER PERFORMANCE AND SHORTER URLS
For the best performance, edit groupsConfig.php to pre-specify groups of files
to be combined under different keys. E.g., here's an example configuration in
groupsConfig.php:
return array(
'js' => array('//js/Class.js', '//js/email.js')
);
This pre-selects the following files to be combined under the key "js":
http://example.com/js/Class.js
http://example.com/js/email.js
You can now serve these files with this simple URL:
http://example.com/min/?g=js

View File

@@ -9,33 +9,10 @@
* For best performance, specify your temp directory here.
* Otherwise Minify will have to load extra code to guess.
*/
$minifyCachePath = 'c:\\xampp\\tmp';
//$minifyCachePath = 'c:\\WINDOWS\Temp';
//$minifyCachePath = '/tmp';
/**
* Manually set the path to Minify's lib folder
*/
//$minifyLibPath = '../lib';
/**
* Set to true to disable the "f" GET parameter for specifying files.
* Only the "g" parameter will be considered.
*/
$minifyGroupsOnly = false;
/**
* Allows specification of base directory via the "b" GET parameter.
* E.g. these are the same:
* ?f=jsFiles/file1.js,jsFiles/file2.js
* ?b=jsFiles&f=file1.js,file2.js
*/
$minifyAllowBase = true;
/**
* If you'd like to restrict the "f" option to files within/below
* particular directories below DOCUMENT_ROOT, set this here.
@@ -44,4 +21,17 @@ $minifyAllowBase = true;
*
* // = DOCUMENT_ROOT
*/
$minifyAllowDirs = array('//js', '//css');
//$minifyAllowDirs = array('//js', '//css');
/**
* Manually set the path to Minify's lib folder
*/
//$minifyLibPath = 'lib';
/**
* Set to true to disable the "f" GET parameter for specifying files.
* Only the "g" parameter will be considered.
*/
$minifyGroupsOnly = false;

View File

@@ -33,9 +33,11 @@ if (isset($_GET['g'])) {
// Groups expects the group key as PATH_INFO
// we want to allow ?g=groupKey
$_SERVER['PATH_INFO'] = '/' . $_GET['g'];
Minify::serve('Groups', array(
'groups' => (require MINIFY_MIN_DIR . '/groupsConfig.php')
));
$serveOpts['groups'] = (require MINIFY_MIN_DIR . '/groupsConfig.php');
if (preg_match('/&\\d/', $_SERVER['QUERY_STRING'])) {
$serveOpts['maxAge'] = 31536000;
}
Minify::serve('Groups', $serveOpts);
} elseif (!$minifyGroupsOnly && isset($_GET['f'])) {
@@ -57,9 +59,7 @@ if (isset($_GET['g'])) {
}
// Version1 already does validation. All we want is to prepend "b"
// to each file if it looks right.
$base = ($minifyAllowBase
&& isset($_GET['b'])
&& preg_match('@^[^/.]+(?:/[^/.]+)*$@', $_GET['b']))
$base = (isset($_GET['b']) && preg_match('@^[^/.]+(?:/[^/.]+)*$@', $_GET['b']))
? '/' . $_GET['b'] . '/'
: '/';
// Version1 expects ?files=/js/file1.js,/js/file2.js,/js/file3.js

31
min/min_group_uri.php Normal file
View File

@@ -0,0 +1,31 @@
<?php
/**
* Function min_group_uri()
*
* @package Minify
*/
require_once dirname(__FILE__) . '/lib/Minify/Build.php';
/**
* Get a timestamped URI to a minified resource using the default Minify install
*
* <code>
* <link rel="stylesheet" type="text/css" href="<?php min_group_uri('css'); ?>" />
* <script type="text/javascript" src="<?php min_group_uri('js'); ?>"></script>
* </code>
*
* @param string $group a key of the array in groupsConfig.php
* @param string $ampersand '&' or '&amp;' (default '&amp;')
* @return string
*/
function min_group_uri($group, $ampersand = '&amp;')
{
static $gc = false;
if (false === $gc) {
$gc = (require dirname(__FILE__) . '/groupsConfig.php');
}
$b = new Minify_Build($gc[$group]);
Minify_Build::$ampersand = $ampersand;
return $b->uri('/' . basename(dirname(__FILE__)) . '/?g=' . $group);
}