0

I'm trying to understand if is it possible 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 want web server response to me with 304 http status code) Is it possible ? Does the expire header works for this way? How?


Of course: Request:

<script scr="my_js.php"></script> 

Response:

<? header("HTTP/1.1 304 Not Modified");
header("Expires: Mon, 31 Dec 2035 12:00:00 gmt");
header("Cache-Control: max-age=".(60*60*24*365)); 
echo "//this is a simpe example"; ?>

Solved

Browser loads resources from his cache without asking them to the web server only the first time you open the page (new tab or new browser window).

The other times browser ALWAYS ask information to the server about the resources saved in his cache. Then, the web server response with 200 or 301.

Community
  • 1
  • 1
alesdario
  • 1,873
  • 6
  • 25
  • 38

2 Answers2

2

Yes, setting a distant expiry header and the asset will not be downloaded again until that expiry.

If you remove the Last-Modified and ETag header, you will totally eliminate If-Modified-Since and If-None-Match requests and their 304 Not Modified Responses, so a file will stay cached without checking for updates until the Expires header indicates new content is available!

Source.

alex
  • 479,566
  • 201
  • 878
  • 984
  • Hi , i'm trying to do the suggestion above in every way but it seem browser always make the _Is-Valid_ request. So, web server always must reponse with some http status code. First time with 200, the other time with 304. – alesdario Jun 21 '11 at 21:48
0

From my htaccess ...

<IfModule mod_headers.c>

    Header unset Pragma
    FileETag None
    Header unset ETag

    # 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"
      Header unset ETag  
      Header unset Last-Modified

    </FilesMatch>

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

</IfModule>

it seems doesn't works .... for example firebug's net panel show me always 200 status code and access.log file report me that external objects are always requested by the browser.

alesdario
  • 1,873
  • 6
  • 25
  • 38