HTTP/1.1 is a old protocol that is being used in modern websites which are very different from the websites of the time HTTP/1.1 was introduced. Therefore a new protocol was required to make the web faster so HTTP/2 was introduced.
As WordPress is the most popular CMS out there it’s important to know what plugins and hacks on a WordPress site can actually slow down the site when its running in an HTTP/2 web server.
In this tutorial I will provide some best practices to follow if your WordPress site is running in HTTP/2 environment. And I will also provide some practices to WordPress developers to follow while creating WordPress plugins and themes.
Is there any Configurations required to make WordPress Run with HTTP/2?
No, you don’t see to make any extra configuration to run WordPress with HTTP/2. Just upgrade your server that’s all needed. WordPress plugins and themes developers also don’t need to make any changes to make them run with in an HTTP/2 Environment.
HTTP/2 is about transporting web pages whereas WordPress is about generating pages dynamically.
Combining JS and CSS Files
We often combine JS, CSS and Image files in a web page to minimize the number of TCP connections opened by browser to fetch them. This is considered as a good practice in HTTP/1.1 but is not required in HTTP/2.2.
HTTP/2.2 has the ability to make multiple HTTP requests and fetch them parallelly using a single TCP connection therefore no need to combine assets.
So prevent using WordPress performance optimization plugins to combine assets.
If you are a WordPress developer then prevent doing this in your code.
Loading Unnecessary Assets
We asynchronously load and cache JS, CSS and other kinds of files which are not required for that particular page but for some other page. This is done to make loading of subsequent pages faster. We assume that user will also visit the other pages so we end up with loading more than what we needed. This is considered a good practice in HTTP/1.1 but not in HTTP/2.
HTTP/2.2 keeps the connection open for sometime so that it can fetch more resources if required a while later therefore no need to include JS and CSS files which are not needed for the current page.
For example, we load sprites which have many images in them which are not required for the current page. So WordPress developers no need to use sprites anymore.
Serving Assets from a Cookieless Domain
The technique is used to minimise the time required to get assets fetch assists. For every HTTP request cookies are sent but while fetching static resources like images, css, js files cookies aren’t required therefore they are served from cookies domain to save bandwidth and time.
HTTP/2 compress headers i.e., cookies are compressed. Therefore the size of HTTP requests are very small compared to HTTP/1.1. So no need to move your assets to a cookies domain.
Other techniques such as using CDN, loading JS and CSS asynchronously, movie JS below content, caching, compressing, minifying, optimizing images etc can still be used to optimize site performance in HTTP/2. No need to make any changes to these things.
If you are a WordPress theme or plugin developer then keep in mind that you no more need to use sprites, combine files or load unnecessary assets in your code.
If you are a WordPress site administrator then do not use optimization plugins to combine files and prevent using themes and plugins which follow the HTTP/2 bad practices.