Slow redirects refer to the process of redirecting a user from
one web page to another, but with significant delays (latency)
in loading time. Slow redirects can negatively impact user
experience and overall website performance.
Redirects can result in latency because the client needs to make
an additional request to the new URL specified in the response
headers. This adds an extra round trip time (RTT) as compared to
directly accessing the desired resource.
Additionally, if there are multiple redirects in place, each
redirection adds further delays as each subsequent request has
to be processed.
Several factors contribute to redirect latency
When a redirect is triggered, whether it's due to a change in
URL structure, domain migration, or simply forwarding users from
an old page to a new one, there is typically some additional
processing time involved before reaching the final destination.
This can impact website performance and user experience.
- Server processing: When a request for
redirection is received by the server, it needs to process
this information and determine where to send the user next.
The server may perform several operations before issuing the
redirect instruction.
- DNS lookups: If the redirected URL involves
switching domains (cross-origin redirects), resolving DNS
(Domain Name System) queries might introduce additional delays
as servers look up IP addresses associated with specific
domain names, establishing TCP connections and TLS (SSL)
handshakes. If any of these steps encounter delays or issues,
it prolongs the overall time taken for serving content to
users.
- Network latency: The physical distance
between client devices and servers introduces network latency
as data travels across various routers and switches. Redirects
involving cross-continental transfers may experience higher
latency compared to those within local networks.
- HTTP request/response cycle: Each redirected
request adds extra steps in the HTTP cycle – initial request
processing, response generation by server-side
scripts/frameworks, transmission of response headers back to
clients – leading to increased overall loading times.
- Caching: Web browsers often cache redirects
temporarily so that subsequent requests do not require
contacting the original server again immediately after
redirection has occurred; however, this caching behavior can
cause issues when updates are made but are not recognized
until cached redirects expire.
Minimize redirect latency
To minimize redirect latency, website owners can optimize their
server configurations, reduce unnecessary redirects, use caching
techniques, and ensure efficient code execution during
redirection processes.
There are several ways to minimize redirect latency and optimize
website performance:
- Use direct links: Instead of using short
URLs, redirecting services, client-side or server-side
redirects, use direct links to the desired webpage. Make sure
all links point directly to the intended destination. If a
redirect is no longer needed or serves no purpose, remove it
from your website's configuration. This eliminates the need
for additional redirects.
- Minimize chained redirects: Avoid having
multiple sequential redirects in your website's architecture
as each redirect adds extra latency overhead. Analyze your
site's structure and eliminate unnecessary intermediaries if
possible.
- Utilize cache mechanisms: Implement caching
mechanisms to store and deliver redirects, so that subsequent
requests can be served directly from cache without invoking
any additional lookups or processing, reducing the need for
repeated server-side processing.
- Optimize server response time: Ensure
efficient hardware configurations and optimized software
settings for faster processing of redirect requests. Improve
the performance of your web server by optimizing code and
server configurations like compression and caching headers to
ensure quick responses when performing a redirect.
- Localize servers: Place servers closer to
user locations or utilize content delivery networks (CDNs) for
reduced network latency.
- Avoid cross-origin redirects: You not only
want to minimise redirects by reducing the number of
same-origin redirects (redirects that occur within the same
domain or origin). You should also aim to keep redirects
within the same origin whenever possible. This means ensuring
that all your necessary redirections occur within your own
domain. By doing so, you eliminate the need for additional DNS
lookups, TCP connections and TLS (SSL) handshakes, and
minimize any latency introduced by cross-origin redirects. A
cross-origin redirect happens when a web page on one origin
redirects to a URL belonging to a different origin. For
example, if a user visits "www.example.com" and gets
redirected to "www.anotherdomain.com", it is considered a
cross-origin redirect.
- Offloading redirects to the server-level:
Offloading redirects to the server-level means that the task
of handling redirects is handled by the web server itself,
rather than at the application-level or CMS-level. Handling
redirects at the server level reduces overhead on the
application or CMS, allowing them to focus on serving content
and processing requests more efficiently. Server-level
redirects are typically faster as they bypass any additional
processing required by applications or CMS platforms. Managing
redirects directly at the server level offers a centralized
approach, making it easier to configure and maintain
redirection rules across multiple websites or applications
hosted on that server. By moving redirect management away from
applications or CMS platforms, there is less chance for
misconfigurations or mistakes that could lead to incorrect
redirections.
- Offloading redirects to the edge: Instead of
handling the redirects on the server-side, they are handled by
a content delivery network (CDN), preferably edge servers
close to the user. On average, latency redirects at a CDN may
add anywhere from 10 milliseconds to a few hundred
milliseconds of extra delay. However, CDNs are designed to
optimize this process and minimize redirect times as much as
possible.
- Use the X-Redirect-By header: The
X-Redirect-By header is a non-standard HTTP response header
that can be used to indicate the method or technology by which
a redirect was performed. It primarily helps in debugging and
understanding the redirection process. By using this header,
it is easy to indicate the system that set the redirect, which
helps to optimise, remove or update redirects.
- Use the HSTS header: The HTTP Strict
Transport Security (HSTS) header is used to improve the
security of web applications by enforcing secure connections
over HTTPS. By utilizing HSTS, websites can provide a more
seamless experience for users, it instructs the browser to
always load the webpage over HTTPS, even if the user types
"http://" in the address bar or clicks on an insecure link.
This eliminates additional latency when redirecting the user
from HTTP to HTTPS. When a browser receives an HSTS header
from a website, it remembers this information and
automatically loads the webpage over HTTPS in subsequent
visits. However, this behavior does not apply to the first
visit to that particular website. To enable HSTS for the
initial visit as well, you can add your domain to the preload
list used by browsers.
Are there thresholds for slow redirects?
In general, lower latency is preferred for a better user
experience and faster website loading times.
When measuring redirect latency, each individual redirect in a
sequence is measured separately. This means that if there are
multiple redirects involved in getting from the initial URL to
the final destination URL, each redirect will have its own
latency measurement.
According to httpstatus.io, the following redirect latency
thresholds for a single redirect can be used as a general
guideline:
- Good:
Below 100ms - Redirect latency below 100ms is
considered good and indicates a fast redirection process with
minimal delay in the redirection process.
- Moderate:
Between 100ms and 300ms - While not ideal, this range
is still considered acceptable for most cases. However, there
may be a noticeable delay in the redirection process.
- Poor:
Above 300ms - Redirect latencies exceeding this
threshold are generally considered poor and can significantly
impact user experience. Users may experience frustrating
delays before being redirected to their desired destination.
Keep in mind that these thresholds are not set in stone and can
vary depending on the specific context or industry standards.
Additionally, it's important to consider other factors such as
network speed and device capabilities when evaluating redirect
latency.
Overall, while redirects are sometimes necessary for various
reasons like website restructuring or handling outdated URLs,
they introduce extra steps that can slow down page load times
and impact user experience. Minimizing redirect latency is
crucial in providing a seamless user experience by reducing
unnecessary waiting times during navigation between web pages or
URLs.