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

利用瀏覽器緩存和 CakePHP

Leverage Browser Caching and CakePHP(利用瀏覽器緩存和 CakePHP)
本文介紹了利用瀏覽器緩存和 CakePHP的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我問我的主人他們是否支持 mod_expires,他們告訴我支持.我使用 CakePHP 并在 webroot/.htaccess 和 `app_root/.htaccess 中嘗試了以下代碼,但考慮到 css、js、png、jpg 等緩存存在問題,Google 的頁面速度很慢.它找到了他們 24 小時!如下圖所示

<FilesMatch ".(ico|pdf|flv|jpg|jpeg|png|gif|js|css|swf)$">標頭集緩存控制max-age=31449600, public"</FilesMatch>

以上代碼摘自.在 cakePHP 1.3+ 中,主題視圖資產已從 app/webroot/themed/themeTitle 移動到 app/views/themed/themeTitle/webroot.

根據 CakePHP 1.3 文檔 您可以通過創建 app/webroot/theme/themeTitle 來恢復主題靜態資??產的舊位置(即在主 webroot 中)

<塊引用>

鏈接到靜態資產與 1.2 略有不同.你還可以使用現有的 app/webroot/themed 并直接鏈接到那些靜態文件.應該注意的是,您需要使用完整路徑鏈接到 app/webroot/themed 中的資產.如果你想保留你的主題在 app/webroot 中的 assets 建議您 重命名app/webroot/themed 到 app/webroot/theme.這將使您能夠利用核心幫助程序路徑查找.以及保持性能不通過 PHP 提供資產的好處.

所以,我為解決這個問題所做的是將 app/views/themed/slate/webroot 中的所有文件復制到 app/webroot/theme/slate

以下屏幕截圖來自 FireFox Firebug,顯示圖像文件在一年后以秒為單位過期:

I asked my host if they supports mod_expires or not, they told me that it is supported. I use CakePHP and I tried the following code in webroot/.htaccess and `app_root/.htaccess but Google's page speed is stile considering there is issue in caching of css, js, png, jpg, etc. it found them 24 hour! as the screenshot shows below

<FilesMatch ".(ico|pdf|flv|jpg|jpeg|png|gif|js|css|swf)$">
Header set Cache-Control "max-age=31449600, public"
</FilesMatch>

The above code is adopted from this article.

Also I used the following:

<IfModule mod_expires.c>
 ExpiresActive On
 ExpiresByType image/jpg "access 1 year"
 ExpiresByType image/jpeg "access 1 year"
 ExpiresByType image/gif "access 1 year"
 ExpiresByType image/png "access 1 year"
 ExpiresByType text/css "access 1 year"
 ExpiresByType text/html "access 1 month"
# ExpiresByType application/pdf "access 1 month"
 ExpiresByType text/x-javascript "access 1 year"
 ExpiresByType text/javascript "access 1 year"
 ExpiresByType application/javascript "access 1 year"
# ExpiresByType application/x-shockwave-flash "access 1 month"
# ExpiresByType image/x-icon "access 1 year"
 ExpiresDefault "access 1 year"
</IfModule>

Also I tried to use both codes with each other but the Google Speed tell me the same. Look at the following screen shot:

I need to know how could I solve this issue?!!

Edit##

Using firebug in Firefox I noticed that only resources in the app/views/themed/slate/webroot are not be affected with the cache settings regarded above, but those found directly in app/webroot , i.e without, theming are affected well.

解決方案

It seems to be a bug in cakephp. In cakePHP 1.3+ the themed view assets have been moved from app/webroot/themed/themeTitle to app/views/themed/themeTitle/webroot.

According to CakePHP 1.3 documentation you are able to restore the old place (i.e. in the main webroot) of the themed static assets by creating app/webroot/theme/themeTitle

Linking to static assets is slightly different from 1.2. You can still use the existing app/webroot/themed and directly link to those static files. It should be noted that you will need to use the full path to link to assets in app/webroot/themed. If you want to keep your theme assets inside app/webroot it is recommended that you rename app/webroot/themed to app/webroot/theme. This will allow you to leverage the core helper path finding. As well as keep the performance benefits of not serving assets through PHP.

So, what I have done for solve this issue is to copying all files in app/views/themed/slate/webroot to app/webroot/theme/slate

The following screen shot is from FireFox Firebug that shows an image file get the expire after one year in seconds:

這篇關于利用瀏覽器緩存和 CakePHP的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持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 字節))
主站蜘蛛池模板: 亚洲一区电影 | 成人片网址 | 国产精品99久久久久久www | 91色视频在线观看 | 久久久久国产 | 欧美日韩成人 | 日本精品一区二区在线观看 | 91欧美精品成人综合在线观看 | 国产又色又爽又黄又免费 | 成年免费大片黄在线观看岛国 | 欧美视频成人 | 蜜臀久久 | 久久青草av | 日韩毛片中文字幕 | 国产一区二区三区视频免费观看 | 成人高清在线视频 | 成人一区二区三区 | 综合色久 | 国产激情视频 | 一本一道久久a久久精品综合 | 欧美二级 | 奇米四色影视 | 成人综合视频在线观看 | 国产精品亚洲一区 | 亚洲欧洲在线观看视频 | 欧洲av在线 | 欧美日一区 | 99久久精品国产麻豆演员表 | 中文字幕一区二区三区在线观看 | 91在线网站| 国产精品久久久久久久久久免费看 | 亚洲福利网站 | 亚洲在线 | av黄色免费在线观看 | 91就要激情 | 天堂网色 | 超碰男人天堂 | 日韩久久久一区二区 | 日韩久久久久久 | 午夜资源| 日本一区二区三区视频在线 |