I have successfully implemented expires headers however, for several days I have been stumped by one thing. This article: http://www.tipsandtricks-hq.com/how-to-add-far-future-expires-headers-to-your-wordpress-site-1533 states

Keep in mind that when you use expires header the files are cached in the browser until it expires so do not use this on files that changes frequently.

Other sites indicate the same in my reading. But this doesn't seem to be true. I have updated an image, using the same name, several times. Each time I update and refresh my browser, the new image (with the same name) displays. I understand from this article that the old image should display unless I use a new name.

Do you happen to know where the misunderstanding is?

I have verified that the image in question has expires headers set on it:

Request Headers:

Host               domain.com
User-Agent         Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.6; en-US; rv: Gecko/20120306 Firefox/3.6.28 FirePHP/0.5
Accept             image/png,image/*;q=0.8,*/*;q=0.5
Accept-Language    en-us,en;q=0.5
Accept-Encoding    gzip,deflate
Accept-Charset     ISO-8859-1,utf-8;q=0.7,*;q=0.7
Keep-Alive         115
Connection         keep-alive
Referer            http://domain.com/index.php
Cookie             __utma=1.61479883.1332439113.1332783348.1332796726.4;     __utmz=1.1332439113.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none);PHPSESSID=lv2hun9klt2nhrdkdbqt8abug7; __utmb=; __utmc=1; ck_authorized=true
x-insight          activate
If-Modified-Since  Mon, 26 Mar 2012 21:55:33 GMT
Cache-Control      max-age=0

Response Headers:

Date           Mon, 26 Mar 2012 22:06:50 GMT
Server         Apache/2.2.3 (CentOS)
Connection     close
Expires        Wed, 25 Apr 2012 22:06:50 GMT
Cache-Control  max-age=2592000

Relevant config (.htaccess):

<IfModule mod_expires.c>
    # Enable Expires Headers for this directory and sub directories that don't override it
    ExpiresActive on

    # Set default expiration for all files
    ExpiresDefault "access plus 24 hours"

    # Add Proper MIME-Type for Favicon
    AddType image/x-icon .ico

    # Set specific expriation by file type
    ExpiresByType application/javascript "access plus 1 month"
    ExpiresByType application/x-javascript "access plus 1 month"
    ExpiresByType text/javascript "access plus 1 month"
    ExpiresByType image/jpg "access plus 1 month"
    ExpiresByType image/gif "access plus 1 month"
    ExpiresByType image/jpeg "access plus 1 month"
    ExpiresByType image/png "access plus 1 month"
    ExpiresByType image/x-icon "access plus 1 month"
    ExpiresByType image/ico "access plus 1 month"
    ExpiresByType image/icon "access plus 1 month"
  • 1
    It might be useful to add the request (GET /foo/bar.png) and the response code (HTTP/1.1 200 OK) to the headers. – Ladadadada Mar 26 '12 at 23:23
  • Can you post the relevant apache config? – LukeR Mar 26 '12 at 23:27
  • @LukeR, I just added "Relevant config (.htaccess)" in my original post. I am still unsure of why caching seems to be ignored. Thank you. – syn4k Mar 27 '12 at 18:05

You seem to be confusing keeping the cached image and using the cached image. The browser keeps the cached image, as configured. However, the browser will not use the cached image if it know it is not current. Revalidation and expiration are two different things.

  • How does the browser know the file in the cache is not the "current" file? Maybe a better question: How can I make the browser always load from cache? Thank you! – syn4k Mar 27 '12 at 18:09

You should use "Cache-Control max-age=2592000, public", so the browser would save the file.

  • What does that do exactly? Thanks. Is it because no max-age is set that I am experiencing this? – syn4k Mar 26 '12 at 23:00
  • No, now the browser would revalidate each time a webpage loads. With public he wouldn't do that again. 2592000 is about a month I guess. – cobra91 Mar 26 '12 at 23:01
  • It would be nice if your answer linked to the appropriate documentation that explained the Cache-Control. – Zoredache Mar 26 '12 at 23:27
  • @cobra91, I introduced this into my .htaccess file however, the cache is still ignored. As a result, I removed this configuration from my .htaccess file. Thanks. – syn4k Mar 27 '12 at 18:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.