Search code examples
gzipgoogle-ajax-apigoogle-cdngoogle-pagespeed

Why (and when) does Google CDN serve jQuery uncompressed?


When I load Google's hosted jquery.min.js, it does not return gzipped:


Request headers

Accept:text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Cache-Control:max-age=0
User-Agent:Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_2) AppleWebKit/534.51.22 (KHTML, like Gecko) Version/5.1.1 Safari/534.51.22

Response headers

Age:262255
Cache-Control:public, max-age=31536000
Content-Length:91668
Content-Type:text/javascript; charset=UTF-8
Date:Fri, 11 Nov 2011 13:06:19 GMT
Expires:Sat, 10 Nov 2012 13:06:19 GMT
Last-Modified:Thu, 22 Sep 2011 14:12:07 GMT
Server:sffe
Vary:Accept-Encoding
X-Content-Type-Options:nosniff
X-XSS-Protection:1; mode=block

Interestingly, jquery-ui.min.js does:


Request headers

Accept:text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Cache-Control:max-age=0
User-Agent:Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_2) AppleWebKit/534.51.22 (KHTML, like Gecko) Version/5.1.1 Safari/534.51.22

Response headers

Cache-Control:private, x-gzip-ok="", max-age=31536000
Content-Encoding:gzip
Content-Length:52140
Content-Type:text/javascript; charset=UTF-8
Date:Mon, 14 Nov 2011 13:55:50 GMT
Expires:Mon, 14 Nov 2011 13:55:50 GMT
Last-Modified:Thu, 22 Sep 2011 14:12:07 GMT
Server:sffe
Vary:Accept-Encoding
X-Content-Type-Options:nosniff
X-XSS-Protection:1; mode=block

What's the deal?

I found an article claiming Google disregards Accept-Encoding and looks at User-Agent to decide whether to compress or not. This doesn't explain why latest Safari and Chrome on Mac OS X get uncompressed jQuery (and compressed jQuery UI).


Solution

  • Here's my request headers:

    Accept:text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
    Accept-Charset:ISO-8859-1,utf-8;q=0.7,*;q=0.7
    Accept-Encoding:gzip, deflate
    Accept-Language:en-gb,en;q=0.5
    Connection:keep-alive
    Host:ajax.googleapis.com
    User-Agent:Mozilla/5.0 (Windows NT 6.1; WOW64; rv:8.0) Gecko/20100101 Firefox/8.0
    

    I get the following response headers:

    Cache-Control: private, x-gzip-ok="", max-age=31536000
    Content-Encoding: gzip
    Content-Length: 32103
    Content-Type: text/javascript; charset=UTF-8
    Date: Mon, 14 Nov 2011 13:28:31 GMT
    Expires: Mon, 14 Nov 2011 13:28:31 GMT
    Last-Modified: Thu, 22 Sep 2011 14:12:07 GMT
    Server: sffe
    Vary: Accept-Encoding
    X-Content-Type-Options: nosniff
    X-XSS-Protection:1; mode=block
    

    Looks like it's gzip by default, as long as the encoding is accepted.