Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

i'm trying to understanding if is it possibile to avoid request for some embedded objects, loading them directly from cache without asking to web server if the object is valid or not (i don't wont web server response to me with 304 http status code) Is it possible ? Does the expire header works for this way? How?

From my htaccess.

    # cache images/pdf docs for 10 days
    <FilesMatch "\.(ico|pdf|jpg|jpeg|png|gif|js)$">

      Header set Expires "Mon, 31 Dec 2035 12:00:00 gmt"


    # cache html/htm/xml/txt diles for 2 days
    <FilesMatch "\.(html|htm|xml|txt|xsl)$">
      Header set Cache-Control "max-age=7200"


Similar operation with php header function and also in httpd.conf.

I verify the results in the apache access.log. Every time i refresh the page in the access.log file appear the 304 request. So, i think the browser always make the request.

share|improve this question

Yes, you should use Expires or Cache-Control: max-age headers to prevent browser from requesting objects again. See RFC 2616 for details.

HTTP caching works best when caches can entirely avoid making requests to the origin server. The primary mechanism for avoiding requests is for an origin server to provide an explicit expiration time in the future, indicating that a response MAY be used to satisfy subsequent requests. In other words, a cache can return a fresh response without first contacting the server.

share|improve this answer
Thanks a lot, but i'm not understanding how control browser cache. By .htaccess , by php' header function, by httpd.conf. Everything i do seems doesn't works. Have you ever done? How? – alesdario Jun 20 '11 at 20:54
@alesdario Better show what you have tried so far and what results you have got. – LazyOne Jun 20 '11 at 23:04
@LazyOne: see the response below. – alesdario Jun 21 '11 at 7:31
See how to set Expires and Cache-Control properly. Also, refreshing page in browser by hitting F5 (or Ctrl-R or reload button) is not proper way to test caching because it forces browser to send If-Modified-Since request. Use FireBug/Chrome network panel to check if server actually sends Expires/Cache-Control headers. – AlexD Jun 21 '11 at 8:24
I've read documentation. I try this solution, but it absolutely doesn't works. ExpiresDefault "access plus 4 weeks" ExpiresByType text/html "access plus 1 month 15 days 2 hours" ExpiresByType image/gif "modification plus 5 hours 3 minutes" ExpiresByType image/jpeg "modification plus 5 hours 3 minutes" – alesdario Jun 21 '11 at 20:18

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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