0

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"

    </FilesMatch>

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

</IfModule>

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.

alesdario
  • 326
  • 1
  • 4
  • 11

1 Answers1

2

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.

AlexD
  • 11,191