Redirect: Location vs Refresh

10

When you use Location and Refresh to redirect.

    header( "Location: www.dominio.com" , TRUE , 302 )
    header( "Refresh:5; url=www.dominio.com" , TRUE , 302 )

Both options produce the same result: redirection . The difference is that Location redirection is instant, while Refresh you can set a delay for redirection.

I want to understand the differences between the two cases when choosing one or the other. Since Refresh has the advantage of choosing the time, I see no direction in Location .

You can set the status 3xx in both cases. The status-code is who informs the redirect cases, so Location and Refresh are just a means to a goal - are they indifferent? p>     

asked by anonymous 09.09.2014 / 04:13

2 answers

9

Both functions serve to redirect / refresh a page, however they have different ways of working.

With Location , the browser does not have to download all the content of the page before making the redirect. This way you will not have problems using the back button of your browser because the function is done server-side.

With the Refresh function you are sending a request to the browser (client-side) to refresh the page. That is, the browser will first download the page and then the time set in the meta tag will redirect the page. In addition, if the user clicks "Back" in the browser it will not work as it should, because it will return to the page where it has just left and will be redirected again.

Location

  • Server-side
  • Do not download website before redirecting

Refresh

  • Client-side
  • You can set time to send to next page
  • It may disrupt the proper functioning of the browser back button
  • Download site content before redirecting

For more information: link

    
09.09.2014 / 12:02
2

To discover the difference we will have to look at this issue from two standpoints, server-side and client-side:

Server-side

For the server there is no difference, it will simply be another HTTP response with status 302 which in the specification is redirection status. "How come it makes no difference?" That's right for the server that imports the request is the response is of interest to the client (disregarding http gateways) so here we realize that we will have to analyze this problem on the client side!

Client-side

Now that we know the problem is here we have to understand something about the HTTP client: For the HTTP client no matter what status and header the server sends, the response will always be downloaded to the client, the responsibility of sending a body or is not on the server, however much the response is in the client's interest, he can not do that. Knowing this we realize that the difference is not in downloading or not the content of the answer!
For those hours you'll ask, "Okay, so what's the difference?" And I would have to respond: "What is your HTTP client? A browser? A JavaScript client? A PHP client? How is it implemented?" What is done with the response headers is the HTTP client's decision! So without knowing your client has no way to know how the behavior will be for each answer.

Conclusion

We realize that the difference will manifest in the HTTP client implementation, so I can not accurately answer the difference! But in general the difference is that the Refresh header was created to display the content of the response prior to the redirect, already the header Location does not display any content however much it has.

    
10.09.2014 / 02:05