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:

http://www.plannedpooling.com/?stitches=65&Color_1=CA2835&Stitches_1=13&Color_2=DD39DE&Stitches_2=16&Color_3=F271B5&Stitches_3=15&type=flat&number_colors_input=3&comment=&old_n_colors=3 

...creates this image:



If you go to "http://www.plannedpooling.com/" (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: http://www.plannedpooling.com.

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?

2 comments:

  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 plannedpooling.com.

    ReplyDelete
  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.

    ReplyDelete