3

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?

rsmoorthy
  • 591
  • 3
  • 7
  • 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

1 Answers1

3

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

rsmoorthy
  • 591
  • 3
  • 7
  • Or don't use Etags. They don't add much anyway in my opinion, which I've explained about in more detail here: https://www.tunetheweb.com/performance/http-performance-headers/etag/#downsides – Barry Pollard Oct 24 '15 at 14:50
  • Thanks @BazzaDP. It is strange that something like ETag is not quite properly implemented in software, that is as prevalent as apache / nginx. – rsmoorthy Oct 29 '15 at 23:29