SPDY Content Compression – How Should it Work?

calendarJune 7, 2012 in Firefox , HttpWatch , Optimization , SPDY

One of the first things we noticed when using HttpWatch in Firefox 13 was that Google servers do not compress content in SPDY responses:

HTTP compression is usually the most important optimization technique a site can use because it drastically reduces the download size of textual resources such as HTML. It therefore seems surprising that the Google servers do not use it with SPDY responses to Firefox.

In fact, the Google home page tries to determine if the browser supports compression by downloading a gzip compressed javascript file to see if it executes. You can see the compression test URL highlighted in the screen shot above.

Normally, a browser indicates that it supports content compression using the Accept-Encoding request header. Firefox 13 doesn’t send this header in SPDY requests. Presumably, Mozilla believes it is not required:

Perhaps, it is the lack of this header that prevents the SPDY enabled Google servers from returning compressed content.

Twitter’s SPDY implementation takes a different approach. It assumes that if the browser supports SPDY then by implication it also supports compression:

So why do Mozilla and Twitter have a different approach to Google over SPDY content compression? The difference is probably down to the way they have interpreted the relevant sections of the SPDY protocol definition.

The SPDY Draft 3 spec has two things to say about compression. First, for headers it clearly states that it is always on: Compression 

The Name/Value Header Block is a section of the SYN_STREAM, SYN_REPLY, and HEADERS frames used to carry header meta-data. This block is always compressed using zlib compression. …

However, for data compression it’s not so easy to work out what is required. The main section about content compression reads as follows:

4.7 Data Compression

Generic compression of data portion of the streams (as opposed to compression of the headers) without knowing the content of the stream is redundant. There is no value in compressing a stream which is already compressed. Because of this, SPDY initially allowed data compression to be optional. We included it because study of existing websites shows that many sites are not using compression as they should, and users suffer because of it. We wanted a mechanism where, at the SPDY layer, site administrators could simply force compression – it is better to compress twice than to not compress.

Overall, however, with this feature being optional and sometimes redundant, it was unclear if it was useful at all. We removed it from the specification.

That suggest that content compression is optional but does say if the client must support it.

In section 3.2.1 there’s a statement that supports the Twitter/Mozilla approach:

User-agents MUST support gzip compression. Regardless of the Accept-Encoding sent by the user-agent, the server may always send content encoded with gzip or deflate encoding.

However, the Overview section seems to imply that the normal Accept-Encoding / Content-Encoding handshake should be used:

SPDY attempts to preserve the existing semantics of HTTP. All features such as cookies, ETags, Vary headers, Content-Encoding negotiations, etc work as they do with HTTP; SPDY only replaces the way the data is written to the network.

The most sensible approach seems to be the one adopted by Mozilla and Twitter. It seems inconceivable that a SPDY aware client would not support content compression given that compression is always used for the headers.

The advantage of forcing all SPDY clients to support content compression is that the Accept-Encoding header is redundant and can be dropped saving a few bytes in each request message.

5 thoughts on “SPDY Content Compression – How Should it Work?

  1. Tarun Reddy says:

    So I’m not see your same headers, but I do see the same Google Response behaviors. Using a competing product (httpwatch doesn’t work on a mac :-( ), I get the following headers to a Google server:

    GET / HTTP/1.1
    Host: http://www.google.com
    User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:13.0) Gecko/20100101 Firefox/13.0
    Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
    Accept-Language: en-us,en;q=0.5
    Accept-Encoding: gzip, deflate
    Connection: keep-alive

    But the response is still not compressed, so the result is the same!

  2. Tarun,

    That’s either not a SPDY request or the tool you are using is not correctly reporting the *actual* SPDY headers.

    For example, all SPDY headers are lower case, there’s always url/method/version headers and there’s no request line (i.e. GET / HTTP/1.1). Firefox does generate an Accept-Encoding header at a higher level but does not transmit it in the SPDY stream.

    If you really want to see what SPDY is doing you need to switch to HttpWatch :)

    BTW. have you seen this:


  3. It could be the absence of accept-encoding. Maybe teir origins do the compression and a proxy is doing SPDY termination.

  4. Jim Roskind says:

    Given that SPDY does Gzip style compression of the headers, it would seem that this change (send vs don’t send ACCEPT-ENCODING: gzip) is not a performance issue to speak of.

    Have folks compared the count of bytes-on-the-wire?

  5. Jim,

    SPDY uses the deflate algorithm with a header friendly dictionary so the compression of headers probably exceeds what you would get with gzip alone.

    You make an interesting point – adding the ‘Accept-Encoding: gzip, deflate’ header would only cost a handful of bytes.

    However, if the SPDY protocol indicated that clients must support content compression it would stop software and hardware vendors opting of compression support during the implementation of SPDY aware hardware and software.

    Tony Gentilcore at Google did a study and found that some software components (e.g. anti-malware scanners) were blocking the Accept-Encoding header so that they didn’t have to cope with compression in HTTP responses. If compression support was mandated by SPDY that would no longer be possible.


Got Something to Say?

Your email address will not be published.

Ready to get started? TRY FOR FREE Buy Now