HTTP/2 vs HTTP 1.1

  • backwards compatible with HTTP/1.1

Features

  • Header Compression: HTTP Header size will be greatly reduced
  • Single Connection. Only one connection to the server is used to load a website, and that connection remains open as long as the website is open. This reduces the number of round trips needed to set up multiple TCP connections.
  • Multiplexing. Multiple requests are allowed at the same time, on the same connection. Previously, with HTTP/1.1, each transfer would have to wait for other transfers to complete. HTTP/2 is especially useful when dealing with TLS connections. The TLS handshake can be quite long but thanks to reduced latency and multiplexing, other requests can do their work without being blocked.
  • HTTP/2 Server Push: Resources can be pushed to the client before they are requested
  • Prioritization: Resources can have dependency levels allowing the server to prioritize which requests to fulfill first
  • Binary: HTTP/2 is a binary protocol making it a lot more efficient when transferring data

Demo

https://www.cloudflare.com/http2/

Deprecated Techniques

With HTTP/1.1, many techniques were used to speed up websites that are no longer necessary with HTTP/2.

  • Domain Sharding. Loading files from multiple subdomains so that more connections may be established. The increase in parallel file transfers adds to server connection overhead.
  • Image Sprites. Combining image files to reduce requests. The file must be loaded before any image from the file can be shown, and the large image file ties up RAM.
  • Combining Files. CSS and JavaScript files are often combined to reduce the number of requests. This makes the user wait for files before any of it can run and consumes additional RAM.
  • Inlining. CSS and JavaScript code, or even images, are placed directly into the HTML, reducing connections but using additional RAM and delays page rendering until the HTML is finished downloading.
  • Cookieless Domains. Static resources like images, CSS and JavaScript files don’t require cookies, so many developers started sending these from a cookieless domain to save bandwidth and time. With HTTP/2, the headers (including cookies) are compressed, so the sizes of the requests are very small in comparison with HTTP/1.1.
  • dealing with REST APIs, you will no longer have to batch requests.
  • Many of the techniques mentioned above by developers placed additional strain on servers due to extra connections opened by browsers. These connection-related techniques are no longer necessary with HTTP/2. The result is lower bandwidth requirements, less network overhead and lower server memory usage.
  • On mobile phones, multiple TCP connections could cause issues with the mobile network, causing them to drop packets and resubmit requests. The additional requests just added to the server load.
  • HTTP/2 itself brings benefits for a server, as well. Fewer TCP connections are necessary, as stated above. HTTP/2 is easier to parse, more compact and less error-prone.

Data Push Illustration

(Image from this blogpost)

Support

  • Cloudflare: free https and HTTP/2 support
  • Chrome and Firefox only supporting HTTP/2 over HTTPS