mirror of
https://github.com/mrclay/minify.git
synced 2025-08-12 09:05:08 +02:00
option changed to "setExpires"
default missing minifier is none (no minification performed)
This commit is contained in:
6
README
6
README
@@ -30,8 +30,8 @@ TESTING
|
|||||||
|
|
||||||
MINIFY OVERVIEW
|
MINIFY OVERVIEW
|
||||||
|
|
||||||
Minify is an HTTP content server. It combines sources of content
|
Minify is an HTTP content server. It compresses sources of content
|
||||||
(usually files), compresses the result and serves it with appropriate
|
(usually files), combines the result and serves it with appropriate
|
||||||
HTTP headers. These headers can usually allow clients to perform
|
HTTP headers. These headers can usually allow clients to perform
|
||||||
conditional GETs (serving content only when clients do not have a valid
|
conditional GETs (serving content only when clients do not have a valid
|
||||||
cache) or tell clients to cache the file until a given date/time.
|
cache) or tell clients to cache the file until a given date/time.
|
||||||
@@ -57,7 +57,7 @@ Minify options (optional). Eg.:
|
|||||||
Minify::serve(
|
Minify::serve(
|
||||||
'Files'
|
'Files'
|
||||||
,array('/path/to/file1.js', '/path/to/file2.js')
|
,array('/path/to/file1.js', '/path/to/file2.js')
|
||||||
,array('cacheUntil' => (time() + 86400 * 365))
|
,array('setExpires' => (time() + 86400 * 365))
|
||||||
);
|
);
|
||||||
|
|
||||||
The above creates an instance of Minify_Controller_Files, passing the
|
The above creates an instance of Minify_Controller_Files, passing the
|
||||||
|
@@ -80,13 +80,13 @@ class HTTP_ConditionalGet {
|
|||||||
? 'public'
|
? 'public'
|
||||||
: 'private';
|
: 'private';
|
||||||
// allow far-expires header
|
// allow far-expires header
|
||||||
if (isset($spec['cacheUntil'])) {
|
if (isset($spec['setExpires'])) {
|
||||||
if (is_numeric($spec['cacheUntil'])) {
|
if (is_numeric($spec['setExpires'])) {
|
||||||
$spec['cacheUntil'] = self::gmtdate($spec['cacheUntil']);
|
$spec['setExpires'] = self::gmtdate($spec['setExpires']);
|
||||||
}
|
}
|
||||||
$this->headers = array(
|
$this->headers = array(
|
||||||
'Cache-Control' => $scope
|
'Cache-Control' => $scope
|
||||||
,'Expires' => $spec['cacheUntil']
|
,'Expires' => $spec['setExpires']
|
||||||
);
|
);
|
||||||
$this->cacheIsValid = false;
|
$this->cacheIsValid = false;
|
||||||
return;
|
return;
|
||||||
|
@@ -4,14 +4,14 @@ require '../../ConditionalGet.php';
|
|||||||
|
|
||||||
// far expires
|
// far expires
|
||||||
$cg = new HTTP_ConditionalGet(array(
|
$cg = new HTTP_ConditionalGet(array(
|
||||||
'cacheUntil' => (time() + 86400 * 365) // 1 yr
|
'setExpires' => (time() + 86400 * 365) // 1 yr
|
||||||
));
|
));
|
||||||
$cg->sendHeaders();
|
$cg->sendHeaders();
|
||||||
|
|
||||||
// generate, send content
|
// generate, send content
|
||||||
$title = 'Expires date is known';
|
$title = 'Expires date is known';
|
||||||
$explain = '
|
$explain = '
|
||||||
<p>Here we set "cacheUntil" to a timestamp or GMT date string. This results in
|
<p>Here we set "setExpires" to a timestamp or GMT date string. This results in
|
||||||
<code>$cacheIsValid</code> always being false, so content is always served, but
|
<code>$cacheIsValid</code> always being false, so content is always served, but
|
||||||
with an Expires header.
|
with an Expires header.
|
||||||
<p><strong>Note:</strong> This isn\'t a conditional GET, but is useful if you\'re
|
<p><strong>Note:</strong> This isn\'t a conditional GET, but is useful if you\'re
|
||||||
|
@@ -96,8 +96,8 @@ class Minify {
|
|||||||
'lastModifiedTime' => self::$_options['lastModifiedTime']
|
'lastModifiedTime' => self::$_options['lastModifiedTime']
|
||||||
,'isPublic' => self::$_options['isPublic']
|
,'isPublic' => self::$_options['isPublic']
|
||||||
);
|
);
|
||||||
if (null !== self::$_options['cacheUntil']) {
|
if (null !== self::$_options['setExpires']) {
|
||||||
$cgOptions['cacheUntil'] = self::$_options['cacheUntil'];
|
$cgOptions['setExpires'] = self::$_options['setExpires'];
|
||||||
}
|
}
|
||||||
|
|
||||||
// check client cache
|
// check client cache
|
||||||
@@ -193,9 +193,7 @@ class Minify {
|
|||||||
,'encodeLevel' => 9
|
,'encodeLevel' => 9
|
||||||
,'perType' => array() // per-type minifier options
|
,'perType' => array() // per-type minifier options
|
||||||
,'contentTypeCharset' => null // leave out of Content-Type header
|
,'contentTypeCharset' => null // leave out of Content-Type header
|
||||||
|
,'setExpires' => null // send Expires header
|
||||||
// @todo: rename option "setExpires" ?
|
|
||||||
,'cacheUntil' => null // send Expires header
|
|
||||||
), $given);
|
), $given);
|
||||||
$defaultMinifiers = array(
|
$defaultMinifiers = array(
|
||||||
'text/css' => array('Minify_CSS', 'minify')
|
'text/css' => array('Minify_CSS', 'minify')
|
||||||
@@ -282,9 +280,10 @@ class Minify {
|
|||||||
$defaultOptions = isset(self::$_options['perType'][$type])
|
$defaultOptions = isset(self::$_options['perType'][$type])
|
||||||
? self::$_options['perType'][$type]
|
? self::$_options['perType'][$type]
|
||||||
: array();
|
: array();
|
||||||
|
// if minifier not set, default is no minification
|
||||||
$defaultMinifier = isset(self::$_options['minifiers'][$type])
|
$defaultMinifier = isset(self::$_options['minifiers'][$type])
|
||||||
? self::$_options['minifiers'][$type]
|
? self::$_options['minifiers'][$type]
|
||||||
: array('Minify', '_trim');
|
: false;
|
||||||
|
|
||||||
if (Minify_Source::haveNoMinifyPrefs(self::$_controller->sources)) {
|
if (Minify_Source::haveNoMinifyPrefs(self::$_controller->sources)) {
|
||||||
// all source have same options/minifier, better performance
|
// all source have same options/minifier, better performance
|
||||||
@@ -292,8 +291,10 @@ class Minify {
|
|||||||
$pieces[] = $source->getContent();
|
$pieces[] = $source->getContent();
|
||||||
}
|
}
|
||||||
$content = implode($implodeSeparator, $pieces);
|
$content = implode($implodeSeparator, $pieces);
|
||||||
self::$_controller->loadMinifier($defaultMinifier);
|
if ($defaultMinifier) {
|
||||||
$content = call_user_func($defaultMinifier, $content, $defaultOptions);
|
self::$_controller->loadMinifier($defaultMinifier);
|
||||||
|
$content = call_user_func($defaultMinifier, $content, $defaultOptions);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
// minify each source with its own options and minifier
|
// minify each source with its own options and minifier
|
||||||
foreach (self::$_controller->sources as $source) {
|
foreach (self::$_controller->sources as $source) {
|
||||||
@@ -304,9 +305,13 @@ class Minify {
|
|||||||
$options = (null !== $source->minifyOptions)
|
$options = (null !== $source->minifyOptions)
|
||||||
? array_merge($defaultOptions, $source->minifyOptions)
|
? array_merge($defaultOptions, $source->minifyOptions)
|
||||||
: $defaultOptions;
|
: $defaultOptions;
|
||||||
self::$_controller->loadMinifier($minifier);
|
if ($defaultMinifier) {
|
||||||
// get source content and minify it
|
self::$_controller->loadMinifier($minifier);
|
||||||
$pieces[] = call_user_func($minifier, $source->getContent(), $options);
|
// get source content and minify it
|
||||||
|
$pieces[] = call_user_func($minifier, $source->getContent(), $options);
|
||||||
|
} else {
|
||||||
|
$pieces[] = $source->getContent();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
$content = implode($implodeSeparator, $pieces);
|
$content = implode($implodeSeparator, $pieces);
|
||||||
}
|
}
|
||||||
@@ -350,19 +355,4 @@ class Minify {
|
|||||||
,self::$_options['perType']
|
,self::$_options['perType']
|
||||||
)));
|
)));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* The default minifier if content-type has no minifier
|
|
||||||
*
|
|
||||||
* This is necessary because trim() throws notices when you send in options
|
|
||||||
* as a 2nd arg.
|
|
||||||
*
|
|
||||||
* @param string $content
|
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
private static function _trim($content, $options)
|
|
||||||
{
|
|
||||||
return trim($content);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@@ -54,7 +54,7 @@ class Minify_Controller_Base {
|
|||||||
* 'contentTypeCharset' : if given, this will be appended to the Content-Type
|
* 'contentTypeCharset' : if given, this will be appended to the Content-Type
|
||||||
* header sent, useful mainly for HTML docs.
|
* header sent, useful mainly for HTML docs.
|
||||||
*
|
*
|
||||||
* 'cacheUntil' : set this to a timestamp or GMT date to have Minify send
|
* 'setExpires' : set this to a timestamp or GMT date to have Minify send
|
||||||
* an HTTP Expires header instead of checking for conditional GET.
|
* an HTTP Expires header instead of checking for conditional GET.
|
||||||
* E.g. (time() + 86400 * 365) for 1yr (default null)
|
* E.g. (time() + 86400 * 365) for 1yr (default null)
|
||||||
* This has nothing to do with server-side caching.
|
* This has nothing to do with server-side caching.
|
||||||
@@ -100,7 +100,7 @@ class Minify_Controller_Base {
|
|||||||
if (! isset($options['contentType'])) {
|
if (! isset($options['contentType'])) {
|
||||||
$options['contentType'] = Minify_Source::getContentType($this->sources);
|
$options['contentType'] = Minify_Source::getContentType($this->sources);
|
||||||
}
|
}
|
||||||
// last modified is needed for caching, even if cacheUntil is set
|
// last modified is needed for caching, even if setExpires is set
|
||||||
if (! isset($options['lastModifiedTime'])) {
|
if (! isset($options['lastModifiedTime'])) {
|
||||||
$max = 0;
|
$max = 0;
|
||||||
foreach ($sources as $source) {
|
foreach ($sources as $source) {
|
||||||
|
@@ -16,7 +16,7 @@ require '../../config.php';
|
|||||||
$serveExtensions = array('css', 'js');
|
$serveExtensions = array('css', 'js');
|
||||||
|
|
||||||
// set HTTP Expires header if GET 'v' is sent
|
// set HTTP Expires header if GET 'v' is sent
|
||||||
$cacheUntil = isset($_GET['v'])
|
$setExpires = isset($_GET['v'])
|
||||||
? (time() + 86400 * 30)
|
? (time() + 86400 * 30)
|
||||||
: null;
|
: null;
|
||||||
|
|
||||||
@@ -40,7 +40,7 @@ if (isset($_GET['f'])) {
|
|||||||
Minify::serve('Files', array(
|
Minify::serve('Files', array(
|
||||||
dirname(__FILE__) . '/' . $filename
|
dirname(__FILE__) . '/' . $filename
|
||||||
), array(
|
), array(
|
||||||
'cacheUntil' => $cacheUntil
|
'setExpires' => $setExpires
|
||||||
));
|
));
|
||||||
exit();
|
exit();
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user