CakePHP高速缓存控件的资产文件(图像,CSS等) [英] CakePHP cache control for asset files (images, CSS, etc)
问题描述
使用CakePHP控制图片和CSS文件的Expires标头的最佳方法是什么?
What's the best way to use CakePHP to control the Expires headers for image and CSS files?
我的主机不支持 mod_expires 或
mod_headers
,所以我不能简单地设置这些值在 .htaccess
。现在没有对我的文件的缓存控制,并且做了很多不必要的请求。
My host unfortunately doesn't support mod_expires
or mod_headers
, so I can't simply set these values in an .htaccess
file. Right now there's no cache control for my files and a lot of unnecessary requests are made.
什么是最优雅的方式通过Cake管理资产文件的请求,并设置适当的标题通过 header()
?
What's the most elegant way to pipe requests for asset files through Cake and set the appropriate headers via header()
?
推荐答案
即使是特定于Cake的方式,也是在 / webroot
中创建一个添加标题的脚本,然后使用 .htaccess
通过该文件的 ./ css / *
和 ./ img / *
的管道请求的指令。我只是希望可能有一些功能像这样内置在蛋糕已经。 :)
I guess the best, not even necessarily Cake-specific way, is to create a script in /webroot
that adds the headers, then use .htaccess
directives to pipe requests for ./css/*
and ./img/*
through that file. I was just hoping there might be some functionality like this built into Cake already. :)
这篇关于CakePHP高速缓存控件的资产文件(图像,CSS等)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!