Re-direction without flickering

Discussion in 'HTML' started by Jens Lenge, Apr 7, 2005.

  1. Jens Lenge

    Jens Lenge Guest

    When I set a re-direction to a different site via

    <meta http-equiv="refresh" content="0; URL=">

    in the header, my current page will be displayed shortly before the
    redirection takes effect, causing an ugly flickering (tested with FF and
    IE6). How can I set the re-direction so that it takes effect *before* the
    current page is displayed?

    I would like the new page to be shown directly (without flickering), and the
    current page be shown only if the re-direction did not work (due to browser
    settings or whatever).

    Any ideas?

    Cheers, Jens
    Jens Lenge, Apr 7, 2005
    1. Advertisements

  2. humbads

    humbads Guest

    If you have scripting support available, use the HTTP 301 response
    code. This far better for search engines too, because then they will
    automatically pick up the new location of the page.

    In ASP-VBScript:

    <%@ Language=VBScript %>
    ' Permanent redirection to
    Response.Status = "301 Moved Permanently"
    Response.AddHeader "Location", ""

    In PHP:

    // Permanent redirection to
    header("HTTP/1.1 301 Moved Permanently");
    humbads, Apr 7, 2005
    1. Advertisements

  3. Andy Dingley

    Andy Dingley Guest

    On Thu, 7 Apr 2005 19:27:07 +0200, "Jens Lenge" <>

    >When I set a re-direction to a different site via
    ><meta http-equiv="refresh" content="0; URL=">
    >in the header, my current page will be displayed shortly before the
    >redirection takes effect,

    There are three ways to do redirection.

    One is at the server, inside the initial HTTP response. This could
    use the ASP Server.Transfer() method. It's not strictly redirection,
    the whole response gets switched into serving content from somewhere
    else. This is often a good way to do things, if you're "Serving
    something from somewhere it isn't obviously at". The client sees
    nothing here - they just get content as if it had arrived from the
    first URL.

    The second is "classic HTTP redirection" The server sends a HTTP 301
    response (sometimes a 302) and the client then performs the
    redirection themselves. You can do this with the ASP
    Server.Redirect() method or for static HTML by configuring .htaccess
    The client may (but probably won't) display much when it follows one
    of these redirections.

    The third is using a http-equiv meta inside a HTML page. This is a
    poor emulation of the second method. It's performed at the client, but
    the client must first obtain the HTML page (which can be slow) and
    parse it. Most clients will also make some attempt at rendering the
    page before following the redirection, and this is what make the
    visible flash.

    So in most cases, do it the second way. Serve a 301 if it's
    permanent, 302 if it's temporary. Google will give you .htaccess
    Andy Dingley, Apr 7, 2005
  4. humbads

    humbads Guest

    humbads, Apr 7, 2005
  5. Jens Lenge

    Jens Lenge Guest

    humbads & Andy,

    Thanks for your comments. From what I learned, it seems that I'll have to
    provide some more details to see which of the suggested methods would be
    best for a case like mine. First, I do have PHP scripting available, and
    also some PHP knowledge. (And I would like to get along with HTML and PHP as
    I have no knowledge about ASP.)

    What I'd like to do on the homepage is:

    1. Use a PHP function to determine the language of the browser.

    2. If the language could be successfully retrieved, automatically forward to
    the specific homepage for that language.

    3. If the language could not be retrieved, or if I have no specific homepage
    for that language, or if the redirection failed due to browser security
    settings, a multi-language "default" homepage is displayed, where the user
    may select his language himself.

    For step 2, I currently use the meta-tag listed in my OP (which results in a
    short flickering es the multi-language page is shortly displayed before the
    language-specific page appears). As far as I learned from your postings, I
    could use PHP to send 301/302 codes instead. I assume if I do this before
    the HTML part of the document, the redirection would take place without
    displaying the page, so it would not flicker. Right?

    However, is it appropriate to use 301/302 codes in this case? After all, I
    do not want to indicate that the site has actually moved temporarily or
    permanently, but only to forward to a specific sub-page within the same

    What do you think?

    Jens Lenge, Apr 7, 2005
  6. Andy Dingley

    Andy Dingley Guest

    On Thu, 7 Apr 2005 23:35:47 +0200, "Jens Lenge" <>

    >I assume if I do this before
    >the HTML part of the document, the redirection would take place without
    >displaying the page, so it would not flicker. Right?


    >What do you think?

    Send a 302
    Andy Dingley, Apr 8, 2005
  7. humbads

    humbads Guest

    Yes, send 302 and it won't flicker when you use the Location header.
    For public websites, it's good to use the appropriate status code
    whenever doing a redirect. For intranet applications or private
    websites, I typically do not bother with sending a status code; I just
    do the redirect by itself.
    humbads, Apr 8, 2005
  8. Jens Lenge

    Jens Lenge Guest

    As far as I googled I can set a 302 redirection by simply setting


    I tried this and found that it works on my local test server (XAMPP/Apache
    on Windows XP), but it does *not* work at my providers' webspace (Strato,
    using Apache on Unix).

    However, I *can* successfully use a similar call for redirecting to the
    *same* page. I have 2 domains that target the same site, and I use the
    following code to make the browser display the name of domain2 also when it
    is called with domain1:

    if ($_SERVER['SERVER_NAME'] != '')

    What could be the reason why the above works perfectly at my providers'
    webspace, but I cannot redirect to a different page? I guess its a matter of
    configuration as it does work for my local server.

    Jens Lenge, Apr 8, 2005
  9. Jens Lenge

    Jens Lenge Guest

    Gaaaaa... just found the solution: I used the header("Location: ...")
    redirection *after* the <html> tag.

    Now I no longer wonder why it did not work at the providers' webspace, but
    rather wonder why it did for my local server. However, now it runs smoothly
    on both servers.

    Thank again for all your advice!

    Jens Lenge, Apr 8, 2005
  10. humbads

    humbads Guest

    Don't worry, that is a very common mistake. I still make it sometimes
    after so many years.

    But you bring up a good point, when I use the Location header by itself
    in PHP/Apache, I get these headers.


    Using Response.Redirect in ASP/IIS results in:


    If I use Response.AddHeader "Location" by itself in ASP/IIS, I get:


    Something, either the web server or the scripting environment, is
    automatically changing the status code when the location header is
    specified. Anyone know what it is? I'm guessing it is the scripting

    Location by itself will always redirect. But I guess to be safe, one
    would want to specify the status code where it needs to be explicit,
    rather than relying on the scripting environment/web server to
    automatically set it.
    humbads, Apr 8, 2005
    1. Advertisements

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. SEWilson

    Re: Flickering effect

    SEWilson, Aug 23, 2003, in forum: ASP .Net
    Aug 23, 2003
  2. yop

    Flickering on Listbox control

    yop, Aug 27, 2003, in forum: ASP .Net
  3. vinay


    vinay, Aug 27, 2003, in forum: ASP .Net
    S. Justin Gengo
    Aug 27, 2003
  4. Georg Andersson

    repaint without flickering

    Georg Andersson, May 17, 2004, in forum: Java
    Silvio Bierman
    May 17, 2004
  5. dhavalshah
    Dec 26, 2008

Share This Page