Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 671465
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T00:22:36+00:00 2026-05-14T00:22:36+00:00

In PHP, I’m trying to steal a page from the Rails playbook (see ‘Using

  • 0

In PHP, I’m trying to steal a page from the Rails playbook (see ‘Using Asset Timestamps’ here):

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).

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:

  # Asset Expiration
  ExpiresActive On
  <FilesMatch "\.(ico|gif|jpe?g|png|js|css)$">
    ExpiresDefault "access plus 1 year"
  </FilesMatch>

If you look at a the source for a Rails page, you’ll see what they mean: the path to a stylesheet might be "/stylesheets/scaffold.css?1268228124", where the numbers at the end are the timestamp when the file was last updated.

So it should work like this:

  1. The browser says ‘give me this page’
  2. The server says ‘here, and by the way, this stylesheet called scaffold.css?1268228124 can be cached for a year – it’s not gonna change.’
  3. On reloads, the browser says ‘I’m not asking for that css file, because my local copy is still good.’
  4. A month later, you edit and save the file, which changes the timestamp, which means that the file is no longer called scaffold.css?1268228124 because the numbers change.
  5. When the browser sees that, it says ‘I’ve never seen that file! Give me a copy, please.’ The cache is ‘busted.’

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.

Now: how do I tell if the caching and cache busting are working?

I’m checking my pages with two plugins for Firebug: Yslow and Google Page Speed. Both seem to say that my files are caching: "Add expires headers" in Yslow and "leverage browser caching" in Page Speed are both checked.

But when I look at the Page Speed Activity, I see a lot of requests and waiting and no ‘cache hits’.

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.

How can I tell?

Update: It’s working!

If anyone’s interested, I just wrote a blog post explaining the details.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T00:22:36+00:00Added an answer on May 14, 2026 at 12:22 am

    In firebug you will see 304 Not Modified for cached pages.

    Check you have implemented these measures in Apache – I’ve found you need a mixture of settings to accommodate all browsers.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

PHP developer here working with c#. I'm using a technique to remove a block
php newbie here..I need some PHP help ideas/examples on how to import data from
PHP 5.2.15 I am trying to replace {date[F]} with the date function. I have
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
PHP Image resize returns only black background. I read all similar posts here, but
PHP Fatal error: Default value for parameters with a class type hint can only
PHP Redirect with Post Data Hi, I am a newbie PHP programmer and trying
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
PHP 5 introduces the magic method __get() and __set(). From my understanding it is
PHP currently will not log errors produced from the command line. I have: log_errors

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.