解决。
首先你必须考虑通过Apache。你可以看看这个指南: http://httpd.apache.org/docs/2.2/caching.html
事情是CakePHP有一个方法来做到这一点。而且非常好。
我会解释这个CSS文件。当然也可以用于JS内容。
1)在你core.php中的文件(在应用程序/配置/)取消注释这一行:
Configure::write('Asset.filter.css', 'css.php');
该行通过“css.php”脚本说把CakePHP路由到CSS文件的所有请求。顾名思义,它是一个过滤器。我们可以做任何我们想做的事情。
2)创建“css.php”文件。你必须在app/webroot/
下创建它你可以获取browsen正在请求的文件并应用一些缓存HTTP头文件。
喜欢的东西:
$filepath = CSS . $regs[1]; //There are some variables that are can be used in this script, take a look to de docs.
$output = file_get_contents($filepath);
header("Date: " . date("D, j M Y G:i:s ", $templateModified) . 'GMT');
header("Content-Type: text/css");
header("Expires: " . gmdate("D, d M Y H:i:s", time() + DAY) . " GMT"); //WEEK or MONTH are valid as well
header("Cache-Control: max-age=86400, must-revalidate"); // HTTP/1.1
header("Pragma: cache"); // HTTP/1.0
print $output;
这就是它!在那里你的内容将与指定的头文件一起提供,浏览器将知道它可以缓存它们。
看看:
http://www.bunchacode.com/programming/get-cakephp-build-in-css-compression-to-work/
有css.php的一个很好的版本,也minfies它。
对于贝克尔的谷歌搜索“为以下资源指定至少一周到期” – givanse