Avoid client-side redirects

Rule from network under performance category

What is a trooper!

we have submitted your edit to the community for review! We'll review and make it live on the site in the next few hours, the internet thanks you :).

Browse another section of the knowledge base



Suggest an edit

Cancel

This rule has no content... yet.

Add content to this rule

Or just browse to view rules that have content



 

Redirects are quite useful but developers/site owners must keep in mind that every redirects adds latency.

Although the latency can be saved using caching, the problem with client-side redirects are that they cannot be cached.

How do I fix this ?

Remove the logic that redirects on the client-side scripts, and rather use the logic server-side as part of the application code or server config. With server-config being the best case here to save more processing time.

Apache can be setup as such:

<VirtualHost *:80>
  ServerName www.domain1.com
  Redirect / http://www.domain2.com
</VirtualHost>

While NGINX can also be configured using:

server {
  listen 80;
  server_name domain1.com;
  return 301 $scheme://domain2.com$request_uri;
}

Both of these examples redirect using 302 (temporary), using 301 (permanent) will allow browsers to fully cache and hit the server again. Usage depends on your scenario.

Resources

Browse another section of the knowledge base



Signup icon
Ready to see how well your site scores?

Passmarked works best when you have an account. It allows you to keep a dashboard with saved data of the sites you have run through the system, we’ll alert you about important updates and you get access to the Passmarked Slack forum.

Sign up to get started