Saturday, April 21, 2012

Chrome is smart about "back" and redirects?

This website I made creates an image based on the parameters in a URL. For example, this url: 

...creates this image:

If you go to "" (with no parameters), I'll make up some  parameters and redirect you a URL like the one below. Unfortunately, this creates a frustrating e xperience with the "back" button (that I'm sure you've experienced elsewhere).

I feel bad about it, but I'vese never fixed that. Probably the best thing would be to make up parameters and show the corresponding image at the root url, without redirecting. Still, I haven't changed that. Sorry world!

But I wondered: Why can't browsers be smart enough to know that when you press the "back" button, you don't want to go back to somewhere that's going to redirect you again.

Then I noticed that Chrome is that smart! Try it:

IE 9 and Safari on my iPad are not that smart, but Safari on my iPhone goes "back" to where I was previously, just like Chrome.

Does anyone know how this is actually working? Does Chrome know that that page redirected me and then not even think about going back to it? Or does it check what's there, and when it sees the redirect decides instead to go back even further? Or something else?


  1. Standard redirection is with a 302 http error code and a "Location" header to say where the browser should go next. Every browser deals with the back button the way you want in that case.

    The redirection you're doing is with javascript. The page loads, messes around a bit, then sends you to another page. Chrome appears to be using some kind of heuristic based on maybe time-to-redirect to determine if you're trying to implement a basic redirect using javascript or sending the user to another page based on an action. For example you could be redirecting because the user did something, in which case the back button should take you back to

  2. Ah, cool. Thanks! That's neat.

    Ah yeah, I guess my reason for doing the "redirect" with javascript is that I'm actually (after populating the form with random colors) submitting the form so the user gets the corresponding image.

    I suppose I should use a standard redirect to the appropriate URL.