HTTP /2 anti-patterns

February 21, 2017 10:33 pm Published by Leave your thoughts

The web has changed dramatically over the last decade, yet the backbone of the web – HTTP, hasn’t been changed. HTTP/1.1 has got various limitations and web developers have always worked around those,

  • Performance issue in terms of bandwidth utilization
  • Performance issue in terms of resource consumption in client and server
  • Web design and maintenance are complex

HTTP/2 tries to solve many shortcomings of HTTP/1.1. It’s main benefits are Multiplexing and concurrency, header compression, server push.

Migration path from HTTP/1.1 to HTTP/2 should be relatively simple, the application and API should continue to work uninterrupted with better performance and consume fewer resources in client and server.

Because HTTP/2 already comes with so many benefits, the workarounds which web developers have been using to achieve similar benefits, become anti-patterns and may cause sub-optimization. If you or your organization is thinking about fully capitalizing on HTTP/2, it is highly recommended to follow few best practices:

  1. Avoid the anti-patterns
    1. Image Spriting – image sprite is a collection of images put into a single image
    2. Inlining Images – Inline image uses data URI to embed image items. Inline images saves HTTP requests over externally referenced objects. Refer link for more details
    3. Domain Sharding – Domain sharding splits resources across subdomains to improve performance. Allow simultaneous resource download at any given time.
    4. Concatenation – like concatenating several Javascript files into single minified Javascript file
  2. Some best practices are still best practices
    1. Reduce DNS lookups – DNS queries could be expensive, especially if you have to start your query at the root nameserver. DNS prefetching via a link rel=’dns-prefetch’ href=’…’ /> line in your document’s head> can help.
    2. Continue to use Content Delivery Network – put your web assets geographically closer to your visitors
    3. Leverage on browser cache – This reduce network traffic. Sometime there are 304 Not modified response happens
    4. Minimize size of HTTP request – Even though HTTP/2 multiplex request, it still takes time to transfer data. So minimize the data size like query string, etc.
    5. Reduce and eliminate unnecessary redirects – Redirect cause unnecessary roundtrip between the browser and the server which in turn adds latency. But sometimes when we redesign or migrate the application, we got to implement few unavoidable redirects, that’s life.

Categorized in:

This post was written by hackya