JavaScript Redirect — Why You Shouldn’t Use Them

Among all the different kinds of redirects out there, there’s one that’s a big SEO pitfall: the JavaScript redirect. The JavaScript redirect is often used by search engine spammers to serve different pages to humans and search engines, a practice known as cloaking.

Using a JavaScript redirect can cause search engines to mistake you for a spammer and downgrade your site accordingly. Why is a JavaScript redirect so looked down upon and what can you do instead? Read on.

=> Why Search Engines Don’t Like JavaScript Redirects

There are a few kinds of code that the Google bots just can’t read very well. These include Java, JavaScript and Flash. Because these are extremely complex programming languages that the Google bot simply isn’t designed to read, search engines often skip over the code completely.

In the past, that left holes in the Google bot. It allowed spammers to put redirects in JavaScript that would send real humans to one site, while displaying content to the search engine bots.

Naturally, Google’s gotten much more sophisticated today about detecting this kind of cloaking. Still, using JavaScript to redirect a user is considered bad form and carries with it some risk of getting penalized by the search engines.

According to Google’s Webmaster Central, using a JavaScript redirect is ok as long as the intent of the code was not to deceive. That said, unless you have a very good reason to use a JavaScript redirect, you should probably just use a different redirect instead.

=> What Kind of Redirect to Use?

There are many different kinds of redirects you can use. Four common ones include the 301 redirect, the 302 redirect, the PHP redirect and the Meta redirect.

The 301 Redirect is also known as a Permanent Redirect. It tells search engines that the page has permanently moved to a new web address and that all rankings, backlinks and PageRanks should be moved accordingly.

The 302 Redirect is considered a temporary redirect. In other words, it’s used by webmasters who want to send users to another page for now, but would want to move it back at some later time.

Keep in mind that these redirects are written at the .htaccess level and won’t cause any speed loss at all. The server never even opens up the old file. Instead, when the user’s browser requests the old page, the server looks up the page, realizes it has moved and instead sends the user the new page. There is no time loss.

The third kind of redirect is the PHP redirect. It’s slightly slower than the 301 or 302 redirect because it has to go through your server’s PHP engine. It’s best used by web applications that need to use code to determine where a user needs to go on a per-case basis, as opposed to a “direct all visitors to a new page” policy.

Finally, the Meta redirect is the slowest of all. It requires the end user to completely load the page with the redirect on it before sending them to a new page. One of the other methods is usually better than a Meta redirect.

In summary, JavaScript redirects are frowned upon by search engines. Though they’re technically not against the rules, there’s no reason to take the risk. Instead, use one of the four alternative redirect types we discussed above.

This article originally appeared here:



Former Digital Social Media Strategist & former Silicon Valley; Living in Ventura, California. Still into Gentle/Yin Yoga and daily walks with Priska, my cat.

Love podcasts or audiobooks? Learn on the go with our new app.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Ana Lucia Novak

Ana Lucia Novak

Former Digital Social Media Strategist & former Silicon Valley; Living in Ventura, California. Still into Gentle/Yin Yoga and daily walks with Priska, my cat.