Chapter 6: Avoid Landing Page Redirects
What are Landing Page Redirects?
PageSpeed Insights recommends you “Avoid Landing Page Redirects.” Redirection occurs anytime a visitor attempts to load a page with a given URL but is sent instead to a different address.
Why Landing Page Redirects Matter
There are many reasons why you might consider redirection:
- The original site has moved, and you want to send the user to where the site is now located
- You want to track clicks and log pages that refer users to your site/sites to which you refer your users
- You want to reserve multiple domains
- You want to secure the information your are sending and receiving, so you switch your users over from using HTTP to HTTPs
However, there may be cases where you have unnecessary redirection on your site:
- Using device-specific versions of your site; for example, a mobile user navigating to http://example.com might be redirected to http://m.example.com/home
- Hyperlinking inconsistently on your site: instead of consistently using URLs with the “www” prefix (such as http://www.example.com) or URLs without the ”www” prefix (such as http://example.com), you mix and match the two, leading to unnecessary redirects
IMPACT OF HTTP REDIRECTION
As an example, we see that the preferred address to access the online edition of the New York Times is http://www.nytimes.com (we received an HTTP response code of 200 when requesting the site). Splunk’s waterfall chart shows that our request took 365 ms to complete.
However, suppose we attempt to load the same site using a slightly different URL: http://nytimes.com. Splunk's waterfall chart indicates that this address has been permanently moved (given that we received an HTTP response code of 301).
Our request for the initial HTML required two steps. The first call was for the resource that we thought was located at http://nytimes.com. This step required 156 ms. We are then redirected to http://www.nytimes.com, which took 365 ms. Because of the redirection, our total HTML request, download, and render time took an additional 156 ms for a total of 521 ms. Additionally, notice how, on the waterfall chart, all of the site’s resources further down on the list are pushed to the right, indicating that the browser handled them at a point of time later than it otherwise would have.
How Landing Page Redirects Work
When implementing site redirection, you can do so using one of two implementations:
- HTTP redirects
We will cover optimization strategies for both implementations.
Using HTTP Redirection
HTTP redirection is typically used to send users to device-specific sites, and this is done by setting the user-agent in the HTTP request headers. The response code for this redirection is either 301 (indicating the redirection is permanent, such as moving users from the address prefixed with “www” to the one that isn’t) or 302 (indicating the redirection is temporary), though you should generally use the latter if it is at all possible.
Identify any other uses of URL redirection on your pages. For example, one type of redirect sends users from the “www” version of the URL to the one without (that is, http://www.example.com redirects to http://example.com). This is similar to the type of redirect used if you’ve registered multiple domains, and you want to direct all of your traffic to your primary URL.
In all of these instances, you should identify which URL garners the most traffic and then configure an HTTP 301-type redirect for all of the lesser-used URLs to the most-trafficked. Implementing this requires access to your server’s .htaccess file. You can find more information about modifying this file within your server’s documentation.
In the best-case scenario, redirection triggers one additional HTTP request-response cycle, which delays page rendering. In the worst-case scenario, it may result in multiple, round-trip request-response cycles including, but not just limited to, DNS lookup, TCP handshake, and TLS negotiation.
Either way, redirection increases the amount of time it takes for your site to render, and you should minimize its use to optimize page performance. If, however, your site requires redirection, you should make sure to implement this so that your users see as little delay as possible.
Notes and Caveats
- When setting up server-side redirection, be sure to keep the redirect URL consistent with the alternate URL specified in the page’s link rel=”alternate” tag or in the Sitemap.
- Because HTTP redirection is handled server-side, it is typically faster than client-side redirection, especially if the browser can cache the new location of the requested file.