我正在尝试加速我网站上的内容。 YSlow警告我,我的图片缺少过期标题。但是我如何在图像上应用这样的标题?
我的应用程序基于zend框架。图像存储在文件夹中的图像,我怎样才能为它们设置过期标题?
答案 0 :(得分:6)
如果您正在使用apache,则可以在httpd.conf
中执行以下操作:
LoadModule expires_module modules/mod_expires.so
ExpiresActive On
ExpiresDefault "access plus 300 seconds"
<Directory "/myProject/webResources">
Options FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
Allow from all
ExpiresByType image/gif "access plus 1 day"
ExpiresByType image/jpg "access plus 1 day"
ExpiresByType image/png "access plus 1 day"
ExpiresByType application/x-shockwave-flash "access plus 1 day"
</Directory>
答案 1 :(得分:1)
昨天我遇到了同样的问题......
所以来自http://framework.zend.com/manual/en/zend.cache.frontends.html的Zend_Cache_Frontend_Page的示例如下所示:
$frontendOptions = array(
'lifetime' => 7200,
'debug_header' => true, // for debugging
'regexps' => array(
// cache the whole IndexController
'^/$' => array('cache' => true),
// cache the whole IndexController
'^/index/' => array('cache' => true),
// we don't cache the ArticleController...
'^/article/' => array('cache' => false),
// ... but we cache the "view" action of this ArticleController
'^/article/view/' => array(
'cache' => true,
// and we cache even there are some variables in $_POST
'cache_with_post_variables' => true,
// but the cache will be dependent on the $_POST array
'make_id_with_post_variables' => true
)
),
'memorize_headers' => array(
'Content-Type',
'Cache-Control',
'Expires',
'Pragma',
)
);
$backendOptions = array(
'cache_dir' => '/tmp/'
);
// getting a Zend_Cache_Frontend_Page object
$cache = Zend_Cache::factory('Page',
'File',
$frontendOptions,
$backendOptions);
$cache->start();