2011-07-19 68 views
1

我想加快我的网站上的东西。 YSlow提醒我我的图片没有过期头文件。但是,我如何在图像上应用这样的标题?如何将缓存控制过期标头添加到图像?

我的应用程序基于zend框架。这些图像也存储在一个文件夹中,我如何能够为它们设置过期标题?

回答

1

我昨天碰到了同样的问题...

  1. 确保您有在生成图像的操作中设置了正确的标题。
  2. 你必须用“的Content-Type”的frontendOptions和性能也“的Cache-Control”和任何你想设置头添加memorize_headers ...

所以对于Zend_Cache_Frontend_Page从http://framework.zend.com/manual/en/zend.cache.frontends.html的例子是看起来像这样:

$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(); 
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> 
相关问题