mirror of
https://github.com/mrclay/minify.git
synced 2025-08-14 18:14:03 +02:00
Oops. It would probably be a good thing if caching actually worked.
This commit is contained in:
40
minify.php
40
minify.php
@@ -177,7 +177,7 @@ class Minify {
|
|||||||
$jsMin = new JSMin($js, false);
|
$jsMin = new JSMin($js, false);
|
||||||
return trim($jsMin->minify());
|
return trim($jsMin->minify());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Rewrites relative URLs in the specified CSS string to point to the correct
|
* Rewrites relative URLs in the specified CSS string to point to the correct
|
||||||
* location. URLs are assumed to be relative to the absolute path specified in
|
* location. URLs are assumed to be relative to the absolute path specified in
|
||||||
@@ -202,7 +202,7 @@ class Minify {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// -- Public Instance Methods ------------------------------------------------
|
// -- Public Instance Methods ------------------------------------------------
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Instantiates a new Minify object. A filename can be in the form of a
|
* Instantiates a new Minify object. A filename can be in the form of a
|
||||||
* relative path or a URL that resolves to the same site that hosts Minify.
|
* relative path or a URL that resolves to the same site that hosts Minify.
|
||||||
@@ -256,16 +256,7 @@ class Minify {
|
|||||||
*/
|
*/
|
||||||
public function browserCache() {
|
public function browserCache() {
|
||||||
$hash = $this->getHash();
|
$hash = $this->getHash();
|
||||||
$lastModified = 0;
|
$lastModified = $this->getLastModified();
|
||||||
|
|
||||||
// Get the timestamp of the most recently modified file.
|
|
||||||
foreach($this->files as $file) {
|
|
||||||
$modified = filemtime($file);
|
|
||||||
|
|
||||||
if ($modified !== false && $modified > $lastModified) {
|
|
||||||
$lastModified = $modified;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$lastModifiedGMT = gmdate('D, d M Y H:i:s', $lastModified).' GMT';
|
$lastModifiedGMT = gmdate('D, d M Y H:i:s', $lastModified).' GMT';
|
||||||
|
|
||||||
@@ -290,7 +281,7 @@ class Minify {
|
|||||||
}
|
}
|
||||||
|
|
||||||
header("Last-Modified: $lastModifiedGMT");
|
header("Last-Modified: $lastModifiedGMT");
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -358,6 +349,26 @@ class Minify {
|
|||||||
public function getHash() {
|
public function getHash() {
|
||||||
return hash('md5', implode('', $this->files));
|
return hash('md5', implode('', $this->files));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the timestamp of the most recently modified file.
|
||||||
|
*
|
||||||
|
* @return int timestamp
|
||||||
|
*/
|
||||||
|
public function getLastModified() {
|
||||||
|
$lastModified = 0;
|
||||||
|
|
||||||
|
// Get the timestamp of the most recently modified file.
|
||||||
|
foreach($this->files as $file) {
|
||||||
|
$modified = filemtime($file);
|
||||||
|
|
||||||
|
if ($modified !== false && $modified > $lastModified) {
|
||||||
|
$lastModified = $modified;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $lastModified;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Removes the specified filename or array of filenames from the list of files
|
* Removes the specified filename or array of filenames from the list of files
|
||||||
@@ -381,7 +392,8 @@ class Minify {
|
|||||||
* @return bool|string
|
* @return bool|string
|
||||||
*/
|
*/
|
||||||
public function serverCache($return = false) {
|
public function serverCache($return = false) {
|
||||||
$cacheFile = MINIFY_CACHE_DIR.'/minify_'.$hash;
|
$cacheFile = MINIFY_CACHE_DIR.'/minify_'.$this->getHash();
|
||||||
|
$lastModified = $this->getLastModified();
|
||||||
|
|
||||||
if (is_file($cacheFile) && $lastModified <= filemtime($cacheFile)) {
|
if (is_file($cacheFile) && $lastModified <= filemtime($cacheFile)) {
|
||||||
if ($return) {
|
if ($return) {
|
||||||
|
Reference in New Issue
Block a user