Take the 2-minute tour ×
Webmasters Stack Exchange is a question and answer site for pro webmasters. It's 100% free, no registration required.

Thank you for posting. Please stand by while you are redirected.

If you are not automatically redirected, please click here.

You're probably familiar with messages like these, especially when using the web in the 90s or early 2000s. In my own projects, I've never found a reason to make the user wait for 2-3 seconds while they are redirected after registration or posting something, for example. But this pattern comes up all the time, even in popular web software like PHPBB.

My question is, does redirection still have a place/need in modern (ajaxy) web development? Are there any situations that absolutely require redirection like this, ultimately annoying the user, and what are the technical reasons behind them? Why not just redirect instantly if a redirect is required?

share|improve this question

migrated from stackoverflow.com Jun 2 '11 at 20:47

This question came from our site for professional and enthusiast programmers.

    
Just a guess: maybe it's somehow related with preventing scripted actions or bots? There are better methods to do that, though (Captchas etc.). –  Martin Matysiak Jun 2 '11 at 20:46
    
Due to user request, I've changed my installation of PHPBB to redirect immediately. It took only a couple of line changes and works perfectly. –  André Paramés Jun 3 '11 at 11:34
    
@Martin: possibly, but if so it's completely misguided, since any bot can follow redirects like any browser (especially if there's a Location header, like in PHPBB). –  André Paramés Jun 3 '11 at 11:36

5 Answers 5

up vote 3 down vote accepted

Are there any situations that absolutely require redirection like this, ultimately annoying the user, and what are the technical reasons behind them?

The most common intent (generally in the case of a request which creates a new record in a database, processes a payment transaction, etc) is the prevention of duplicate requests should the user hit the "Refresh" button and re-post the request.

Does redirection still have a place/need in modern (ajaxy) web development?

If you can get away with telling users who have Javascript disabled that their requests will be ignored or possibly mishandled (the "Do not click submit more than once!" message comes to mind) sure - but it's not a huge effort to support those quirky JS-disabled users and ensure that the billing department doesn't see the occasional double-billing complaint, so redirection of some sort is still implemented in many interfaces.

Why not just redirect instantly if a redirect is required?

The redirect should be issued instantly if the goal is to prevent multiple form submissions - in the case of timed redirects perhaps they're geared toward sluggish servers, they've failed to factor in a session-based lock, or they're trying to solve a more esoteric problem.

share|improve this answer
    
"is the prevention of duplicate requests" --- silent location redirect does that as well. "The redirect should be issued instantly if the goal is to prevent multiple form submissions" --- it shouldn't, because F5 on Stand by page will also cause re-sending post. –  zerkms Jun 3 '11 at 0:51
    
@zerkms - I'm suggesting a redirect to a new location before a response body is sent (i.e. no "stand by" page) –  danlefree Jun 3 '11 at 5:03

I always send a redirect in the response header with the proper HTTP status code (e.g. 301 or 302 - see http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html ), which results in an immediate redirect. I'm not aware of any good technical reasons why someone would display a "please wait while you're redirected page".

share|improve this answer

It also allows the back button to sort of work properly.

share|improve this answer

First of all, not all browsers will redirect when given a Location header. Second, not all browsers will redirect with Javascript because it is disabled. Third, not all browsers will support the meta-refresh tags. Any of these cases is probably very rare so it probably won't matter. But even if it does, you can overlap all of these methods I think.

The way the PHPBB pages does it (waits for 5 seconds or something) is not needed at all. It should redirect immediately and if it doesn't, it will display the HTML page (which has meta-refresh and Javascript on it and text with a link) after sending the headers. There's almost no chance this page will actually get displayed by a regular browser if it's programmed properly.

share|improve this answer
    
"First of all, not all browsers will redirect when given a Location header" [citation needed] –  Jon Cram Jun 2 '11 at 20:51
    
@Jon Cram: technically web proxies, and extensions could interfere with the location header. The browser could also be a non-standard user agent and the site owner is trying to discourage them following offsite links by presenting something that a user can easily follow. –  Brian Lyttle Jun 2 '11 at 20:55
    
Am I reading you correctly in that calling PHP's header() function might actually be ignored? This worries me greatly. I was already aware about the HTML and JS redirection methods and how they are less reliable, but I never actually thought a server-side-sent HTTP header could actually be ignored. –  Lotus Notes Jun 2 '11 at 21:07
1  
@Lotus Many people don't send the header correctly which is the bigger problem. You are supposed to include a 3xx code before it which many people don't do. A browser could ignore this request if it wanted (and I'm sure some clients do; not mainstream browsers though) –  Joe Philllips Jun 2 '11 at 21:11
    
Note also that a Location header is supposed to send an absolute URL, yet this is often ignored. –  Piskvor Jun 3 '11 at 9:54

The main reason for doing this is that a record is made on the site that you have been redirected. The page could load Google Analytics, but the data is also going to be in the weblogs.

If you send a redirect using HTTP headers then the browser will go off to the other site without making any additional requests to the original site. Javascript-based tracking may catch these exits, but it gives the site owner better opportunities for tracking.

In some cases you might also want to provide a disclaimer to the user than they are being redirected. This is particularly important to webmasters working in regulated industries. If you don't work in a regulated industry like banking or pharmaceuticals you will not have much appreciation for these requirements.

share|improve this answer
    
So in summary, this pattern is only necessary if you need to track your users' actions on the website? –  Lotus Notes Jun 2 '11 at 21:10

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.