久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

如何在 CakePHP2 中緩存靜態內容(css、圖像、js 文件

How to cache static content (css, images,js files) in CakePHP2?(如何在 CakePHP2 中緩存靜態內容(css、圖像、js 文件)?)
本文介紹了如何在 CakePHP2 中緩存靜態內容(css、圖像、js 文件)?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我需要設置一些 HTTP 標頭Expires"、Cache-Control"、Last-Modified",用于資源如 CSS 文件、圖像文件、js 文件、等(Webroot 內容).

I need to set some HTTP headers "Expires", "Cache-Control", "Last-Modified", for resources as CSS files, Images files, js files, etc (Webroot content).

我了解到有一些功能,通過

I've read that there's some functionality, through

   Configure::write('Asset.timestamp', true); // In core.php

和 Helper 類的 assetTimestamp 方法.

and the assetTimestamp method of the Helper class.

現在的問題是:它是如何使用的?

Now, the question is: How is it used?

我閱讀了 HtmlHelper 代碼,在 css 方法中,第 361 行是這樣的:

I read the HtmlHelper code and in the css method, line 361 there's this:

$url = $this->assetTimestamp($this->webroot($path));

推薦答案

已解決.

首先你要考慮通過Apache來實現.你可以看看這個指南:http://httpd.apache.org/docs/2.2/caching.html

First of all you have to consider to make it through Apache. You can take a look at this guide: http://httpd.apache.org/docs/2.2/caching.html

CakePHP 有一種方法可以做到這一點.而且還不錯.

The thing is that CakePHP has a method to do this. And is pretty good.

我將為 CSS 文件解釋這一點.當然也可以用于JS內容.

I'll explain this for CSS files. Of course can be used to JS content as well.

1) 在您的 core.php 文件中(在 app/config/下)取消注釋這一行:

1) In your core.php file (under app/config/) uncomment this line:

Configure::write('Asset.filter.css', 'css.php');

該行告訴 CakePHP 通過css.php"腳本將所有請求路由到 CSS 文件.顧名思義,它是一個過濾器.在那里我們可以為所欲為.

That line says to CakePHP to route all requests to CSS files through that "css.php" script. As the name implies, it's a filter. There we can do whatever we want.

2) 創建css.php"文件.您必須在 app/webroot/

2) Create that "css.php" file. You've to create it under app/webroot/

在那里,您可以獲取瀏覽器正在請求的文件并應用一些緩存 HTTP 標頭.

Make there, you can take the file that the browsen is requesting and apply some cache HTTP headers.

類似于:

$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;

就是這樣!在那里,您的內容將使用指定的標頭提供,瀏覽器將知道可以緩存它們.

That's it! There your content will be served with those headers specified and the browser will know that can cache them.

看看:

http://www.bunchacode.com/programming/get-cakephp-build-in-css-compression-to-work/

有一個很好的 css.php 版本,也可以簡化它.

There's a good version of css.php that also minfies it.

這篇關于如何在 CakePHP2 中緩存靜態內容(css、圖像、js 文件)?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

Cannot use #39;Object as class name as it is reserved Cake 2.2.x(不能使用 Object 作為類名,因為它是保留的 Cake 2.2.x)
Session is lost after an OAuth redirect(OAuth 重定向后會話丟失)
Pagination Sort in Cakephp 3.x(Cakephp 3.x 中的分頁排序)
CakePHP Shared core for multiple apps(CakePHP 多個應用程序的共享核心)
Login [ Auth-gt;identify() ] always false on CakePHP 3(在 CakePHP 3 上登錄 [ Auth-identify() ] 始終為 false)
Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 87 bytes)(致命錯誤:允許的內存大小為 134217728 字節已用盡(嘗試分配 87 字節))
主站蜘蛛池模板: 日本视频在线播放 | 蜜桃在线视频 | 日韩一及片 | 亚洲精品视频在线看 | 91婷婷韩国欧美一区二区 | 欧美日韩一区二区视频在线观看 | 国产欧美三区 | 中文字幕在线不卡 | 国产欧美在线播放 | 一级片毛片| 国产精品亚洲二区 | 久久精选| 高清免费在线 | 成人免费在线 | 超碰人人爱 | 91在线电影| 久久精品久久久 | 播放一级毛片 | 亚洲国产日韩欧美 | 日韩欧美三区 | 久久国产精品一区二区 | 色频| 午夜天堂精品久久久久 | 中文在线播放 | 亚洲午夜av久久乱码 | 淫片一级国产 | 亚洲精品在线国产 | 免费的日批视频 | 国产在线观看一区二区三区 | 黄色精品 | 精品九九久久 | 中文字幕在线二区 | 成人免费视频 | 日韩福利 | 精品成人在线视频 | 亚洲精品一区中文字幕乱码 | 免费看一区二区三区 | 99久久精品免费看国产高清 | 男人天堂手机在线视频 | av网站在线播放 | 国产成人网 |