Caching issues and unnecessary browser requests that would trigger a 304 response

Discussion in 'Apache' started by ramow, Nov 20, 2008.

  1. #1
    I am trying to optimize the delivery of my javascript files. I am using the "Header" mod_header directive in the httpf.conf:

    Header add Expires "Mon, 28 Jul 2014 23:30:00 GMT" env=VERSIONED_FILE
    Header add Cache-Control "max-age=315360000" env=VERSIONED_FILE


    As you can see, I am setting the expires and Cache-Control in order to make sure that the browser won't ask for the file again. I am using Firefox.

    Summary: the first time the browser get the file my server sends back the special infinity Expires/Cache-Control. in the header BUT my Firefox always request the file again with a soft refresh. The time to send another request and get a 304 code back is a wasted precious time. How can I solve this problem? Ultimately I want the browser to respect the Expiry date and cache control I have set.

    I know that not all browser respect those value but as long as IE and Firefox are concerned they do respect that by their default settings. SO WHAT's HAPPENING HERE???!?

    Please help!!!

    --Rami


    Here is the firebug output:

    #1:
    --------------------------------------------------------------------------------------------------
    HTTP/1.0 200 OK
    --------------------------------------------------------------------------------------------------
    Response Headers
    Date Fri, 21 Nov 2008 02:50:33 GMT
    Server Apache
    Last-Modified Wed, 19 Nov 2008 04:59:15 GMT
    Etag "9e8436-3f9-45c03ac774ec0"
    Accept-Ranges bytes
    Content-Length 1017
    Expires Mon, 28 Jul 2014 23:30:00 GMT
    Cache-Control max-age=315360000
    Keep-Alive timeout=15, max=100
    Connection Keep-Alive
    Content-Type application/x-javascript

    Request Headers
    Host ##############
    User-Agent Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.0.4) Gecko/2008102920 Firefox/3.0.4
    Accept text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
    Accept-Language en-us,en;q=0.5
    Accept-Encoding gzip,deflate
    Accept-Charset ISO-8859-1,utf-8;q=0.7,*;q=0.7
    Keep-Alive 300
    Connection keep-alive
    Pragma no-cache
    Cache-Control no-cache


    After a soft refresh. (F5 and NOT ctrl+F5)
    #2
    --------------------------------------------------------------------------------------------------
    HTTP/1.0 304 Not Modified
    --------------------------------------------------------------------------------------------------
    Response Headers
    Date Fri, 21 Nov 2008 03:06:28 GMT
    Server Apache
    Last-Modified Wed, 19 Nov 2008 04:59:15 GMT
    Etag "9e8436-3f9-45c03ac774ec0"
    Accept-Ranges bytes
    Content-Length 1017
    Expires Mon, 28 Jul 2014 23:30:00 GMT
    Cache-Control max-age=315360000
    Content-Type application/x-javascript

    Request Headers
    Host ##############
    User-Agent Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.0.4) Gecko/2008102920 Firefox/3.0.4
    Accept text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
    Accept-Language en-us,en;q=0.5
    Accept-Encoding gzip,deflate
    Accept-Charset ISO-8859-1,utf-8;q=0.7,*;q=0.7
    Keep-Alive 300
    Connection keep-alive
    If-Modified-Since Wed, 19 Nov 2008 04:59:15 GMT
    If-None-Match "9e8436-3f9-45c03ac774ec0"
    Cache-Control max-age=0
     
    ramow, Nov 20, 2008 IP
  2. joebert

    joebert Well-Known Member

    Messages:
    2,150
    Likes Received:
    88
    Best Answers:
    0
    Trophy Points:
    145
    #2
    You might as well forget about it. Modern browsers allow visitors to bypass such headers and always check for newer versions of files.

    Just when you think you have it, you're going to get a wash of these visitors and pull your hair out trying to find out what's broken when that's just the way it works.
     
    joebert, Nov 21, 2008 IP