说服浏览器缓存由 JavaScript 更改的 DOM
我有一个网络应用程序,其首页有一个登录表单。当提交登录表单时,一些 JavaScript jiggery-pokery 会在幕后发生,并且用户的数据会出现 - 无需页面加载。
问题在于,当用户离开页面,然后使用后退按钮导航回来时,页面处于原始的非登录状态。我可以让浏览器缓存更改后的 DOM 吗?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以尝试使用这样的插件: http://benalman.com/projects/jquery- bbq-plugin/
你必须在你的url中生成一个#logged链接,当你点击历史记录返回时,你只需要重新请求用户信息。
希望这有帮助。
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.
我大胆猜测,与其将一些在客户端上存储用户登录数据的东西一起破解(无论如何这是一个坏主意),沿着这些思路进行的事情将是一个更好的主意:
修复“jiggery-pokery”,以便它没有损坏。
一旦修复了 jiggery-pokery,您的页面就可以检查该信息并显示“已登录”DOM。
有道理吗?
当前流程:
访问站点
JS登录
更新DOM
新流程:
访问站点
检查是否登录
提供适当的 DOM
JS 登录
后端存储登录信息
JS 更新 DOM。
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:
Fix the "jiggery-pokery" so that it's not broken.
Once the jiggery-pokery is fixed, your page can do a check for that piece of info and present the "logged in" DOM.
Make sense?
Current flow:
Visit site
JS login
Update DOM
New Flow:
Visit Site
Check if logged in
Present appropriate DOM
JS Login
Backend stores login info
JS updates DOM.