Are JavaScript redirects bad for SEO?

If your only means of redirection are JavaScript redirects, then: no. Using JavaScript redirects is much better than not redirecting at all.

From an SEO point of view, a JavaScript redirect is not the most optimal way of redirecting because search engines need to render a page to find the redirect. Redirecting using a 301 redirect is always recommended (except if you’re looking to temporarily redirect).

JavaScript redirects are often picked up by search engines, and they do pass authority.

If you do need to use JavaScript redirects, make sure to send consistent signals by:

  1. Including the redirect target in the XML sitemap.
  2. Update internal links to point to the redirect target.
  3. Update any canonincal URLs to point to the redirect target.

Implementing JavaScript redirects

The recommended function to redirect is window.location.replace().

An example of what a JavaScript redirect to our homepage looks like:

<html>
	<head>
		<script>
			window.location.replace("https://www.contentkingapp.com/");
		</script>
	</head>
</html>

This code would send a visitor to https://www.contentkingapp.com/ upon page load.

The benefit of using the window.location.replace function is that the current URL isn’t added to the visitor’s navigation history, whereas the popular JavaScript redirect window.location.href would. That could cause a visitor to get stuck in back-button loops. Therefore, don’t use it when redirecting visitors immediately to another URL.

<script>
	window.location.href='https://www.contentkingapp.com/';
</script>
ContentKing Academy

Read the full Academy article to learn everything about Redirects

Start your free 14-day trial

Get up and running in 20 seconds

Please enter a valid domain name (www.example.com).
  • No credit card required
  • No installation needed
  • No strings attached