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:
- Including the redirect target in the XML sitemap.
- Update internal links to point to the redirect target.
- Update any canonical 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.conductor.com/"); </script> </head> </html>
This code would send a visitor to https://www.conductor.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.conductor.com/'; </script>
Keep learning