0

I have a web app, on the front page of which there is a login form. When the login form is submitted, some JavaScript jiggery-pokery happens behind the scenes and the user's data appears -- without a pageload.

The problem is that when the user navigates away from the page, then uses the back button to navigate back, the page is in its original, non-logged-in state. Can I have the browser cache the altered DOM?

nornagon
  • 15,393
  • 18
  • 71
  • 85

2 Answers2

0

You could try using a plugin like this one: http://benalman.com/projects/jquery-bbq-plugin/

You have to generate a #logged link into your url, when you click on history back you just have to re-request the user information.

Hope this helps.

alexl
  • 6,841
  • 3
  • 24
  • 29
0

I would venture to guess that instead of hacking something together that stores user login data on the client (which is a bad idea anyway), something along these lines would be a much better idea:

  1. Fix the "jiggery-pokery" so that it's not broken.

    • What I mean is: it's not REALLY logging the users in, it's just giving them the illusion of being logged in
    • So you need to change it so that it stores some piece of information (probably in the session) that verifies that they are logged in.
  2. Once the jiggery-pokery is fixed, your page can do a check for that piece of info and present the "logged in" DOM.

    • If they're not logged in, it still uses the old JS method to show the original, log them in, and update the DOM (the first time).

Make sense?

Current flow:

  1. Visit site

  2. JS login

  3. Update DOM

New Flow:

  1. Visit Site

  2. Check if logged in

  3. Present appropriate DOM

  4. JS Login

  5. Backend stores login info

  6. JS updates DOM.

rockerest
  • 10,412
  • 3
  • 37
  • 67
  • The browser doesn't make a request to the server when the back button is pressed, since the page is cached. I'm trying to avoid setting no-store in `Cache-control`. – nornagon Apr 29 '11 at 11:02
  • Well, the solution to that is to have the Javascript check for whether the user is logged in before the page loads, so if they are, it then presents the logged-in DOM. That still doesn't fix the broken login system, though :-/ Giving the illusion of logging in seems like it's going to create a lot more headaches down the road. – rockerest Apr 29 '11 at 20:21
  • It's not an illusion -- I really have set a cookie in their browser. I just want to fade things in instead of having a jarring pageload. – nornagon May 02 '11 at 01:18