diff --git a/README b/README index a71a359..d6bdd31 100644 --- a/README +++ b/README @@ -30,8 +30,8 @@ TESTING MINIFY OVERVIEW -Minify is an HTTP content server. It combines sources of content -(usually files), compresses the result and serves it with appropriate +Minify is an HTTP content server. It compresses sources of content +(usually files), combines the result and serves it with appropriate HTTP headers. These headers can usually allow clients to perform 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. @@ -57,7 +57,7 @@ Minify options (optional). Eg.: Minify::serve( 'Files' ,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 diff --git a/lib/HTTP/ConditionalGet.php b/lib/HTTP/ConditionalGet.php index d275afe..d41879c 100644 --- a/lib/HTTP/ConditionalGet.php +++ b/lib/HTTP/ConditionalGet.php @@ -80,13 +80,13 @@ class HTTP_ConditionalGet { ? 'public' : 'private'; // allow far-expires header - if (isset($spec['cacheUntil'])) { - if (is_numeric($spec['cacheUntil'])) { - $spec['cacheUntil'] = self::gmtdate($spec['cacheUntil']); + if (isset($spec['setExpires'])) { + if (is_numeric($spec['setExpires'])) { + $spec['setExpires'] = self::gmtdate($spec['setExpires']); } $this->headers = array( 'Cache-Control' => $scope - ,'Expires' => $spec['cacheUntil'] + ,'Expires' => $spec['setExpires'] ); $this->cacheIsValid = false; return; diff --git a/lib/HTTP/ConditionalGet/test/5.php b/lib/HTTP/ConditionalGet/test/5.php index 64e317b..2b2f0f0 100644 --- a/lib/HTTP/ConditionalGet/test/5.php +++ b/lib/HTTP/ConditionalGet/test/5.php @@ -4,14 +4,14 @@ require '../../ConditionalGet.php'; // far expires $cg = new HTTP_ConditionalGet(array( - 'cacheUntil' => (time() + 86400 * 365) // 1 yr + 'setExpires' => (time() + 86400 * 365) // 1 yr )); $cg->sendHeaders(); // generate, send content $title = 'Expires date is known'; $explain = ' -

Here we set "cacheUntil" to a timestamp or GMT date string. This results in +

Here we set "setExpires" to a timestamp or GMT date string. This results in $cacheIsValid always being false, so content is always served, but with an Expires header.

Note: This isn\'t a conditional GET, but is useful if you\'re diff --git a/lib/Minify.php b/lib/Minify.php index e5005c7..63a80c8 100644 --- a/lib/Minify.php +++ b/lib/Minify.php @@ -96,8 +96,8 @@ class Minify { 'lastModifiedTime' => self::$_options['lastModifiedTime'] ,'isPublic' => self::$_options['isPublic'] ); - if (null !== self::$_options['cacheUntil']) { - $cgOptions['cacheUntil'] = self::$_options['cacheUntil']; + if (null !== self::$_options['setExpires']) { + $cgOptions['setExpires'] = self::$_options['setExpires']; } // check client cache @@ -193,9 +193,7 @@ class Minify { ,'encodeLevel' => 9 ,'perType' => array() // per-type minifier options ,'contentTypeCharset' => null // leave out of Content-Type header - - // @todo: rename option "setExpires" ? - ,'cacheUntil' => null // send Expires header + ,'setExpires' => null // send Expires header ), $given); $defaultMinifiers = array( 'text/css' => array('Minify_CSS', 'minify') @@ -282,9 +280,10 @@ class Minify { $defaultOptions = isset(self::$_options['perType'][$type]) ? self::$_options['perType'][$type] : array(); + // if minifier not set, default is no minification $defaultMinifier = isset(self::$_options['minifiers'][$type]) ? self::$_options['minifiers'][$type] - : array('Minify', '_trim'); + : false; if (Minify_Source::haveNoMinifyPrefs(self::$_controller->sources)) { // all source have same options/minifier, better performance @@ -292,8 +291,10 @@ class Minify { $pieces[] = $source->getContent(); } $content = implode($implodeSeparator, $pieces); - self::$_controller->loadMinifier($defaultMinifier); - $content = call_user_func($defaultMinifier, $content, $defaultOptions); + if ($defaultMinifier) { + self::$_controller->loadMinifier($defaultMinifier); + $content = call_user_func($defaultMinifier, $content, $defaultOptions); + } } else { // minify each source with its own options and minifier foreach (self::$_controller->sources as $source) { @@ -304,9 +305,13 @@ class Minify { $options = (null !== $source->minifyOptions) ? array_merge($defaultOptions, $source->minifyOptions) : $defaultOptions; - self::$_controller->loadMinifier($minifier); - // get source content and minify it - $pieces[] = call_user_func($minifier, $source->getContent(), $options); + if ($defaultMinifier) { + self::$_controller->loadMinifier($minifier); + // get source content and minify it + $pieces[] = call_user_func($minifier, $source->getContent(), $options); + } else { + $pieces[] = $source->getContent(); + } } $content = implode($implodeSeparator, $pieces); } @@ -350,19 +355,4 @@ class Minify { ,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); - } } diff --git a/lib/Minify/Controller/Base.php b/lib/Minify/Controller/Base.php index d3a0968..a6ce291 100644 --- a/lib/Minify/Controller/Base.php +++ b/lib/Minify/Controller/Base.php @@ -54,7 +54,7 @@ class Minify_Controller_Base { * 'contentTypeCharset' : if given, this will be appended to the Content-Type * 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. * E.g. (time() + 86400 * 365) for 1yr (default null) * This has nothing to do with server-side caching. @@ -100,7 +100,7 @@ class Minify_Controller_Base { if (! isset($options['contentType'])) { $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'])) { $max = 0; foreach ($sources as $source) { diff --git a/web/examples/1/m.php b/web/examples/1/m.php index 4013522..ff4cce5 100644 --- a/web/examples/1/m.php +++ b/web/examples/1/m.php @@ -16,7 +16,7 @@ require '../../config.php'; $serveExtensions = array('css', 'js'); // set HTTP Expires header if GET 'v' is sent -$cacheUntil = isset($_GET['v']) +$setExpires = isset($_GET['v']) ? (time() + 86400 * 30) : null; @@ -40,7 +40,7 @@ if (isset($_GET['f'])) { Minify::serve('Files', array( dirname(__FILE__) . '/' . $filename ), array( - 'cacheUntil' => $cacheUntil + 'setExpires' => $setExpires )); exit(); }