title: How can I test caching and cache busting?
body: <p>In PHP, I'm trying to steal a page from the Rails playbook (see 'Using Asset Timestamps' <a href="http://api.rubyonrails.org/classes/ActionView/Helpers/AssetTagHelper.html" rel="nofollow noreferrer">here</a>):</p>
  <blockquote>
  <p>By default, Rails appends assets'
  timestamps to all asset paths. This
  allows you to set a cache-expiration
  date for the asset far into the
  future, but still be able to instantly
  invalidate it by simply updating the
  file (and hence updating the
  timestamp, which then updates the URL
  as the timestamp is part of that,
  which in turn busts the cache).</p>
  <p>It‘s the responsibility of the web
  server you use to set the far-future
  expiration date on cache assets that
  you need to take advantage of this
  feature. Here‘s an example for Apache:</p>
  </blockquote>
  <pre><code>  # Asset Expiration
    ExpiresActive On
    &lt;FilesMatch &quot;\.(ico|gif|jpe?g|png|js|css)$&quot;&gt;
      ExpiresDefault &quot;access plus 1 year&quot;
    &lt;/FilesMatch&gt;
  </code></pre>
  <p>If you look at a the source for a Rails page, you'll see what they mean: the path to a stylesheet might be <code>&quot;/stylesheets/scaffold.css?1268228124&quot;</code>, where the numbers at the end are the timestamp when the file was last updated.</p>
  <p>So it should work like this:</p>
  <ol>
  <li>The browser says 'give me this page'</li>
  <li>The server says 'here, and by the way, this stylesheet called <code>scaffold.css?1268228124</code> can be cached for a year - it's not gonna change.'</li>
  <li>On reloads, the browser says 'I'm not asking for that css file, because my local copy is still good.'</li>
  <li>A month later, you edit and save the file, which changes the timestamp, which means that the file is no longer called <code>scaffold.css?1268228124</code> because the numbers change.</li>
  <li>When the browser sees that, it says 'I've never seen that file! Give me a copy, please.' The cache is 'busted.'</li>
  </ol>
  <p>I think that's brilliant. So I wrote a function that spits out stylesheet and javascript tags with timestamps appended to the file names, and I configured Apache with the statement above.</p>
  <p>Now: <strong>how do I tell if the caching and cache busting are working?</strong></p>
  <p>I'm checking my pages with two plugins for Firebug: Yslow and Google Page Speed. Both seem to say that my files are caching: &quot;Add expires headers&quot; in Yslow and &quot;leverage browser caching&quot; in Page Speed are both checked.</p>
  <p>But when I look at the Page Speed Activity, I see a lot of requests and waiting and no 'cache hits'.</p>
  <p>If I change my stylesheet and reload, I do see the change immediately. But I don't know if that's because the browser never cached in the first place or because the cache is busted.</p>
  <p>How can I tell?</p>
  <h2>Update: It's working!</h2>
  <p>If anyone's interested, I just wrote <a href="http://sleeplessgeek.blogspot.com/2010/03/rails-caching-and-cache-busting-in-php.html" rel="nofollow noreferrer">a blog post explaining the details</a>.</p>