title: Enable Gzip compression and set Cache expire times in CakePHP
body: <p>I am using CakePHP with Apache2. Analyzing my pages with the tool PageSpeed from Google, I find two main problems. The first is that I should enable gzipping of content, the second that I should leverage browser caching for images, javascript and css files.</p>
  
  <p>I have more or less found how to remedy this, but it involves changing my main .htaccess file. This doesn't look really the CakePHP way, if nothing because that .htaccess is part of the CakePHP distribution, and I have to remember to keep it when changing version. Is there a better way to do this?</p>
  
  <p>For the first, I can remedy by putting</p>
  
  <pre><code>php_value output_buffering On
  php_value output_handler ob_gzhandler
  </code></pre>
  
  <p>I also tried</p>
  
  <pre><code>&lt;IfModule mod_deflate.c&gt;
      AddOutputFilterByType DEFLATE text/html text/plain text/css text/javascript application/x-javascript
  &lt;/IfModule&gt;
  </code></pre>
  
  <p>but I didn't see any result with PageSpeed.</p>
  
  <p>For the second I now use</p>
  
  <pre><code>&lt;IfModule mod_expires.c&gt;
      ExpiresActive On
      ExpiresByType application/x-javascript A8640000
      ExpiresByType text/javascript A8640000
      ExpiresByType text/css A8640000
      ExpiresByType image/png A8640000
  &lt;/IfModule&gt;
  </code></pre>
  
  <p>and it kind of works, although I still get the message "The following cacheable resources have a short freshness lifetime. Specify an expiration at least one month in the future for the following resources: blah blah"</p>