I'm going cross eyed looking at all the HTTP headers available for controlling the caching of content.

What headers do I need to set I I want content to be cached:

  • For at most 24 hours (or any time period I choose)
  • With no re-validation
  • With no etags

I've realized that browsers are re-requesting my CSS, JS, and images on every page view. I want them to be able to cache these items for some amount of time without checking back in at all with my site.

My server does not support "if modified since" nor "etags". I have implemented a versioning system where the version of the resource is in the file name, so I can cache bust when the files are changed.

  • Which headers are currently being sent that appear to break the cache? Generally, a server default should at least allow some caching of these resources?
    – MrWhite
    Sep 30, 2016 at 17:11
  • I have tried Expires: <timestamp 24 hours in the future> which doesn't appear to make Firefox cache anything at all without wanting to revalidate Sep 30, 2016 at 17:21

1 Answer 1


The Expires header is the simplest. If you're using Apache you can set this by mime type using mod_expires. In your .htaccess:

<IfModule mod_expires.c>
    ExpiresActive On
    ExpiresByType text/css "access plus 1 day"
    ExpiresByType image/png "access plus 1 day"
  • I'm not using Apache, so your .htaccess code isn't all that helpful to me. I did have the Expires header set 24 hours from the request, but that doesn't seem to stop Firefox from sending more requests for the same resource in that time period. It is sending them with an "If modified since" header and expecting a 304 not modified response. My server doesn't support 304 responses, so I'm looking for a cache directive that prevents requests for revalidation Sep 30, 2016 at 16:02
  • Apache's mod_expires primarily sets the max-age directive of the Cache-Control header - this is the important one supported by all modern browsers. In addition, mod_expires also sets the corresponding Expires header - but this is only for older browsers. The Cache-Control header will take priority in all browsers that support it.
    – MrWhite
    Sep 30, 2016 at 17:08
  • How are you testing for revalidation? If your server isn't sending etags or last modified headers in the response, but you are sending the Expires header I wouldn't expect browsers to re-request unless you hit refresh. Sep 30, 2016 at 17:19
  • When I testing I'm using refresh (but not shift-refresh) on a page and watching the log files for images, JS, and CSS. Sep 30, 2016 at 17:50
  • Yeah, some browsers will re-request the files if you do that. Instead, navigate to a page that includes the resources, then click a link to another page with the same resources. See if they get re-requested. You might find it's working after all. Sep 30, 2016 at 18:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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