How to Achieve Redirect Optimization with CDNetworks

November 12, 2024
CDN-Redirect-Optimization

Contents

Try CDNetworks For Free

Most of our products have a 14 day free trial. No credit card needed.

Share This Post

CDN redirect optimization refers to the process of using CDN (Content Delivery Network) technology to automatically redirect access requests to the most optimal CDN PoP based on factors like the user’s geographical location and network environment. This improves access speed and user experience. When a 302 redirect is required during an origin fetch, the redirect optimization feature allows the CDN to directly return the file retrieved after the 302 redirect to the user and cache it. When the origin server responds with a 4xx or 5xx error, the error page redirection feature allows the CDN to return a pre-agreed customized page to the user, providing a more user-friendly response. This reduces user access time, lowers the perception of errors, improves user experience, enhances operational flexibility, and reduces costs.

CDNetworks Redirect Optimization Strategy

CDNetworks’ redirect optimization feature plays a key role in improving user access speed, optimizing resource management, and enhancing user experience. Through various optimization measures, CDNetworks effectively addresses common issues such as redirect latency, error page handling, and duplicate resource requests, thereby significantly improving network performance.  

Origin 302 Redirect Optimization

For many business requests, there are situations where the origin server returns a 301/302 response, but the origin server does not want the 301/302 to be directly passed through to the end user. To address this, the ‘Redirect Optimization’ feature can be used. If the origin server returns an HTTP status code of 301/302, CDNetworks CDN PoPs can request the file based on the target URL specified in the Location header of the HTTP 301/302 response. The CDN then returns the file to the user and caches it on the CDN PoP. This process hides the redirection from the user, eliminating the need for the user to make an additional request to the URL after the 301/302, thus speeding up user access.

Error Page Redirection

When a user initiates a request and the origin server encounters an issue, directly returning a 4xx or 5xx error status to the front end can result in a very poor user experience. To address this issue, the ‘Error Page Redirection’ feature can be used. When a CDN PoP makes a request to the origin server and receives a 4xx or 5xx error status code, the CDNetworks edge PoP will return a response with an HTTP status code of 302 to the client, with the Location header indicating the redirect page for the error. When the user’s browser receives this response, it will make a request to the URL specified in the Location header, thereby providing a more user-friendly error page and preserving the user experience.

Embedded URL Rewriting

A typical HTML page contains resources that need to be loaded separately (such as images, text files, CSS, JavaScript, etc.). When a user requests this page, these resources are loaded along with the page and cached locally. If the user refreshes the page after the max-age time has expired, new HTTP requests for these static resources will be sent. If the files have not expired, the server returns a 304 response, allowing the cached version to be used directly, but this still incurs some response time overhead. If the files have expired, the server returns the new resources.

To address this, the ‘Embedded URL Rewriting’ feature can be used to prevent the client from making requests for unexpired files, saving time between sending requests and receiving responses, thus reducing the page load time for the client. The specific method involves rewriting the embedded URLs in the HTML page to include specific information about the resources (referred to as a PV value), and modifying the HTTP response headers to allow resources to be cached locally for up to one year. When the server updates the resources, the URLs of the resources change (reflected by a change in the PV value), and the outdated cached resources will no longer be used.

Implementation Guide

Origin 302 Redirect Optimization

Usage method: Inform the CDNetworks customer service of the redirect optimization requirements and provide an example of the target URL. CDNetworks will complete and test this configuration within one day.

Note:

  • The redirected URL must be accessible via CDN (for instance, if the domain information in the redirected URL is an IP address)
  • This feature is applicable when the target URL of the redirect is also accelerated by the CDN, or when the origin server uses redirection for load control
  • It is disabled by default

Error Page Redirection

Usage: You need to inform CDNetworks customer service of your specific requirements, providing the error status code and the URL to redirect to (i.e., which page to redirect to).

Note:

  1. If the redirection is to a URL under the same domain, the redirected URL must exist; otherwise, it will return a 404 error and may lead to a loop of redirects.
  2. This feature can be used in conjunction with the origin server’s 301/302 redirection optimization feature, allowing the client to receive a 200 redirect page directly instead of the expected 302 redirect to an error page, thereby further enhancing the user experience.

Embedded URL Rewriting

The specific approach is to rewrite the embedded URLs in the HTML page to include specific information about the resources (referred to as the PV value). When the server modifies the resource, the resource’s URL will also change (reflected by the change in the PV value), and the old resources in the cache will not be used. At the same time, the HTTP response headers will be rewritten so that the resource can be cached locally by the user for one year. For example:

HTML tag: <img src=”images/logo.gif”/> 

HTTP header: Cache-Control;public,max-age=300

Will be modified to:

HTML tag: <img src=”images/logo.gif;pv=12345678″/> 

HTTP header: Cache-Control;public,max-age=31536000

The CDN PoP will continue to use the original max-age value of the resource (e.g., 300 seconds in the previous example) to determine whether the resource has expired. If the resource changes, the corresponding PV value will also be updated, and a new URL will be provided to the accessing user. When the resource has not changed, users will continue to access the local cache of the CDN, avoiding unnecessary resource requests and thus improving page loading speed.

Note:

  1. This feature is one of the page rewriting functions, so it also needs to meet the conditions for page rewriting.
  2. Embedded URL rewriting is effective for cacheable pages and will not take effect for non-cacheable pages.

Key Benefits

CDNetworks CDN redirection provides several important benefits:

  • Origin server 301/302 redirection optimization is completed by the CDN, eliminating the connection time for users to initiate a request to the 301/302 redirect URL, thereby speeding up user access.
  • Error page redirection allows for the display of a more user-friendly prompt page on the front end when the origin server returns a 4xx or 5xx error, ensuring a better user experience.
  • Embedded URL rewriting enables CDN to handle the detection of updates for externally embedded resources in HTML pages, reducing client-side page loading time.

Why Choose CDNetworks?

CDNetworks is one of the global leaders in Content Delivery Network (CDN) technology, offering fully integrated Edge Computing and Cloud Security solutions. With an expansive network of over 2,800 Points of Presence (PoPs) and CDN capabilities exceeding 200 Tbps, we ensure your content is delivered with exceptional speed and reliability. Through strategic partnerships with ISPs worldwide and our comprehensive optimization features, we help businesses enhance their user experience while reducing server load and operational costs.

More To Explore

HTTP Header Optimization
Uncategorized

How CDNetworks Helps Optimize HTTP Headers

HTTP headers are key-value pairs sent in HTTP requests and responses, providing essential information about the communication between the client and server. They include details such as content type, encoding, cache control, authentication, and more,

Read More »