1

私は自分のサイトで物事をスピードアップしようとしています。YSlowは、画像に有効期限ヘッダーがないことを警告します。しかし、どうすればそのようなヘッダーを画像に適用できますか?

私のアプリケーションはzendフレームワークに基づいています。画像は画像と同様にフォルダに保存されますが、それらの有効期限ヘッダーを設定するにはどうすればよいですか?

4

2 に答える 2

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>
于 2011-07-19T09:45:40.033 に答える
1

昨日、同じ問題に遭遇しました...

  1. 画像を生成するアクションに適切なヘッダーが設定されていることを確認してください。
  2. 「Content-Type」を含むmemorize_headersをfrontendOptionsに追加する必要があり、パフォーマンスのために「Cache-Control」と設定したいヘッダーをすべて追加する必要があります...

したがって、 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();
于 2011-07-19T12:05:29.377 に答える