2

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?

  • I think the max-age=0 in the request forces the document to be served fresh and not cached – Dan Oct 23 '15 at 15:39
  • I used curl to exactly simulate the above request, but without Cache-control in the request. Still the response is not a 304. But then, I changed the request header to If-None-Match:"6f344-51a6ce0fcb040" (without "-gzip").. and lo!, I got 304 as response. – rsmoorthy Oct 23 '15 at 16:37
2

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\""
    

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.