Apache2 – Why caching of a static file is not happening

apache-2.4http-headerssugarcrm

I am working on to cache static files in a SugarCRM environment, which is not happening as I would like to.

I have narrowed it to one specific case, and I would like to know why this is so.

On the Chrome browser, I am trying to access this URL directly:


http://hostname/cache/include/javascript/sugar_grp1_jquery.js

The request headers, on subsequent visits:

Accept:text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
Accept-Encoding:gzip, deflate, sdch
Accept-Language:en-US,en;q=0.8,zh-CN;q=0.6,zh;q=0.4
Cache-Control:max-age=0
Connection:keep-alive
Cookie:PHPSESSID=dlbb4vtum36n37teu9eqpd1pf7; sugar_user_theme=SuiteR
Host:hostname
If-Modified-Since:Thu, 09 Jul 2015 08:16:57 GMT
If-None-Match:"6f344-51a6ce0fcb040-gzip"
Upgrade-Insecure-Requests:1
User-Agent:Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/45.0.2454.101 Safari/537.36

The response headers are like:

HTTP/1.1 200 OK
Date: Fri, 23 Oct 2015 15:20:58 GMT
Server: Apache/2.4.16 (Ubuntu)
Last-Modified: Thu, 09 Jul 2015 08:16:57 GMT
ETag: "6f344-51a6ce0fcb040-gzip"
Accept-Ranges: bytes
Vary: Accept-Encoding
Content-Encoding: gzip
Keep-Alive: timeout=5, max=94
Connection: Keep-Alive
Transfer-Encoding: chunked
Content-Type: application/javascript

I was expecting HTTP Status Code 304 (not modified). Why is this not happening?

Best Answer

Looks like this is a Apache bug. As noted in SO link:

This is a known bug in Apache. See Apache bug #45023, and summary of Apache 304 etags and mod_deflate.

And the work-around, for now, is as noted in the above SO link,

  • enable mod_headers
  • place these in .htaccess or apache config:

     RequestHeader  edit "If-None-Match" "^\"(.*)-gzip\"$" "\"$1\""
     Header  edit "ETag" "^\"(.*[^g][^z][^i][^p])\"$" "\"$1-gzip\""
    

Related Topic