title: Stop browser to make HTTP requests for images that should stay cached - mod_expires
body: <p>After reading many articles and some questions on here, <strong>I finally succeded in activating the Apache <code>mod_expires</code> to tell the browser it MUST cache images for 1 year</strong>.</p>
  
  <pre><code>&lt;filesMatch "\.(ico|gif|jpg|png)$"&gt;
    ExpiresActive On
    ExpiresDefault "access plus 1 year"
    Header append Cache-Control "public"
  &lt;/filesMatch&gt;
  </code></pre>
  
  <p>And thankfully server responses seem to be correct:</p>
  
  <pre><code>HTTP/1.1 200 OK 
  Date: Fri, 06 Apr 2012 19:25:30 GMT 
  Server: Apache 
  Last-Modified: Tue, 26 Jul 2011 18:50:14 GMT 
  Accept-Ranges: bytes 
  Content-Length: 24884 
  Cache-Control: max-age=31536000, public 
  Expires: Sat, 06 Apr 2013 19:25:30 GMT
  Connection: close
  Content-Type: image/jpeg 
  </code></pre>
  
  <p>Well, I thought this would stop the browser to download and even inquire the server about the images for 1 year. But it's partially true: cause <strong>if you close and reopen the browser, the browser does NOT download the images</strong> from server anymore, <strong>but browser still inquires the server with an HTTP request for each image</strong>.</p>
  
  <p><strong>How do I force browser to stop making HTTP requests for each image? Even if these HTTP requests are not followed by an image being downloaded, they are still requests made to the server</strong> that unecessarely icrease latency and slow down the page rendering!</p>
  
  <p>I already told the browser it MUST keep the images in cache for 1 year! Why does browser still inquire the server for each image (even if it does not download the image)?!</p>
  
  <hr>
  
  <p>Looking at network graphs in FireBug (menu FireBug > Net > Images) I can see different caching behaviours (I obviously started with the browser cache completly empty, I forced a cache delete on browser using "Clear All History"):</p>
  
  <ul>
  <li><p><strong>When the page is loaded for the 1st time all images are downloaded</strong> (and same thing happens if I force a page reload by clicking on the browser's reload page button). <em>This makes sense!</em></p></li>
  <li><p><strong>When I navigate the site and get back to the same page</strong> the images are not downloaded at all and the <strong>browser does NOT even inquire the server</strong> for any of the images. <em>This makes sense, (and I would like to see this behaviour also when browser is closed)!</em> </p></li>
  <li><p><strong>When I close the browser and open it again on the same page, the silly browser makes anyway HTTP request to the server one time per image: it does NOT downalod the image, but it still makes an HTTP request, it's like the browser inquires the server about the image</strong> (server replies with 200 OK). <em>This is the one that irritates me!</em> </p></li>
  </ul>
  
  <p>I also attach the graphs below if you are interested:</p>
  
  <p><img src="https://i.stack.imgur.com/5HKaq.jpg" alt="enter image description here"></p>
  
  <p><img src="https://i.stack.imgur.com/WQk1S.jpg" alt="enter image description here"></p>
  
  <p>EDIT: just tested now also with FireFox 11.0 just to make sure it wasn't an issue of my FireFox 3.6 being too old. The same thing happens!!! <strong>I also tested Google site and Stackoverflow site</strong>, they do both send the <code>Cache-Control: max-age=...</code> but <strong>the browser still makes an HTTP request to the server for each image once the browser is closed and opened again on the same page</strong>, after server response the browser does NOT download the image (as I explained above) but it still makes the damn request that increases time to see page.</p>
  
  <p>EDIT2: and removing the <code>Last-Modified</code> header as suggested <a href="http://www.askapache.com/htaccess/apache-speed-last-modified.html" rel="noreferrer">here</a>, does not solve the problem, it does not make any difference.</p>