Jump to content

Alternatives to redirect


proggR

Recommended Posts

I'm wondering if there's any alternatives to redirecting.

 

For example, after the registration process, I have a fully loaded User object with all of the information I need to load the user's profile (the place that logging in/registering takes you to). I can call the profile action of the user controller and pass in the User object and it will display just fine. The problem is that since the URL is still pointing to the register action if the user refreshes their page its going to try sending the previous form again.

 

Alternatively I could redirect to the profile and have it load that way, but then I'm fetching data from the database seemingly unnecessarily since I had all of the data I needed already fetched prior to redirecting.

 

Is there anyway that I could do the first process but change the url and forget the previous form data so that if they refresh its just refreshing the profile and not resending the previous request?

 

Thanks in advance for any help.

Link to comment
Share on other sites

If you don't redirect then the URL will not change, and to make the URL change you must redirect.

 

Alternatively I could redirect to the profile and have it load that way, but then I'm fetching data from the database seemingly unnecessarily since I had all of the data I needed already fetched prior to redirecting.

Not a problem.

Link to comment
Share on other sites

If you don't redirect then the URL will not change, and to make the URL change you must redirect.

 

Alternatively I could redirect to the profile and have it load that way, but then I'm fetching data from the database seemingly unnecessarily since I had all of the data I needed already fetched prior to redirecting.

Not a problem.

 

I thought this may be the case. Its unfortunate since its an extra database request that otherwise wouldn't need to be made but if I must I must I suppose.

 

Thanks for clearing that up.

Link to comment
Share on other sites

Its unfortunate since its an extra database request that otherwise wouldn't need to be made but if I must I must I suppose.

Just a drop in the ocean. If one extra database request per signup was bad then you'd have more problems than just efficient code.

 

True enough. The same thing happens on signin and one other type of content creation but nothing major. And ya, one extra request isn't the end of the world, I just figured if there was a more efficient way to do it I'd like to do it that way. Thanks again :)

Link to comment
Share on other sites

Slow code for something that gets executed once in a while isn't as bad as slow code for something executed often.

 

Optimize for the majority of your traffic, even if it means slowing down other, lesser used requests.

Link to comment
Share on other sites

Not these days. There is such a thing as pushState(). See https://developer.mozilla.org/en/DOM/Manipulating_the_browser_history

Imagine that: yet another way to deceive your users!

 

Why would HTML 5 include such a thing? What good uses does it have that don't involve tricking users into thinking they're in one place when they're actually in another?

Link to comment
Share on other sites

Without trying to rant (but it just comes so easily and I'm really tired right now), why? People won't be able to share URLs because they'll be looking at the wrong one. XSS attacks could change the referrer, redirect someplace malicious, and capture information. Clicking in the address bar and hitting enter won't reload the page but send me somewhere else instead.

 

Are they doing this to try to address the whole reloading-a-POSTed-form issue? There's already a great solution to that and it's been built into HTTP since 1.0.

Honestly, what good does this do? What's the use case? What problem is it solving?

Link to comment
Share on other sites

Urls simply point to resources. Just because a url is /foo what about that means you need to be on a page/script named foo? You just need to know that the url points to the resource you want.

 

An awesome example if this is on Github's site. Goto https://github.com/trq/proem, click the lib directory then drill down to wherever. The url changes without an entire page refresh. But guess what? You can now bookmark something like https://github.com/trq/proem/blob/develop/lib/Proem/Application.php. Even though you are really on https://github.com/trq/proem, the resource is easy to locate.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.