0

I'm trying to serve up some JS and CSS files from Amazon CloudFront using Gzip. Following their instructions, it seems that I'm supposed to determine if the client supports Gzip when rendering my page, and if so, I append .gz to the file URL.

The problem is that when I inspect browser requests, they do seem to add Accepts-Encoding:gzip (or deflate) headers to requests for JS or CSS files, but not for the HTML file. The HTML request is where I need to read the header. The JS or CSS requests are going to CloudFront, not my server.

So, if I see / in the Accept-Encoding for the HTML request, is it safe to assume the clients supports gzip?

Josh Pearce
  • 3,399
  • 1
  • 23
  • 24

2 Answers2

1

According to RFC 2616, section 14.1, The asterisk "*" character is used to group media types into ranges, with "*/*" indicating all media types.....

Read more about this here http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html

In short Accept-Encoding: */* means all media types are accepted and Accept-Encoding: gzip means gzip compression is accepted.

Community
  • 1
  • 1
Robert Christopher
  • 4,940
  • 1
  • 20
  • 21
1

Not exactly. While */* means the client claims "I'll accept anything", I could invent a new encoding this afternoon that nothing on the planet will accept, and watch as browsers that accept "anything" fail to handle it. (For a (content-type) Accept header, / makes more sense, because browsers can always just save the file).

That said, support for gzip encoding is extremely widespread, so it is safe to assume that any client claiming to accept it (or accept "anything") will support it.

Quentin
  • 914,110
  • 126
  • 1,211
  • 1,335
  • Thanks for the answer. I'm really in a bit of a pickle since, as far as I can tell, Amazon CloudFront requires that I render different URLs for gzip'd files in their CDN. The only request I can read the headers from to decide, is the request for the HTML page, since the rest of the content is served from the CDN. Clients don't seems to send Accept-Encoding: gzip, for HTML. My concern is that some mobile devices don't like gzip. – Josh Pearce Aug 12 '14 at 10:51