Storing persistent data in browser

前端 未结 5 1610
[愿得一人]
[愿得一人] 2020-12-11 23:05

For my web application, I need to store form inputs spanning across multiple pages, until I finally process/manipulate them to produce some results (its mostly formatting th

相关标签:
5条回答
  • 2020-12-11 23:29

    Hitting the storage limit of the cookie could indicate you are trying to store too much on the client side. It might be prudent to store it serverside, in something like a session. The key to the session could then be stored in a cookie.

    An alternative method is to not have the requests span multiple pages, and just store the data on the client side, not as a cookie, but as different form fields and/or text fields (they could be hidden). The merit of such a method is it doesnt hit the cookie limit as you have. It also makes your serverside code easier/cleaner, since it doesn't have to keep track of state (something you'd always have to do if spanning across pages, and thus the reason you are hitting the cookie limit in the first place).

    0 讨论(0)
  • 2020-12-11 23:36

    Use webstorage (you can client-side store around 5MB of text or binary data)

    Firefox demo: http://codebase.es/test/webstorage.html

    DOM Storage is supported in these web browsers:

    • Internet Explorer 8
    • Firefox 2 for sessionStorage, 3.5 for localStorage
    • Safari 4

    Just google for sessionStorage and localStorage objects.

    Also modern webkit browsers supports client-side sql.

    Edit:
    I'm not sure about what you want to do but using AJAX you can store everything in javascript variables and serverside databases or sessions are a good choice.

    0 讨论(0)
  • 2020-12-11 23:40

    You could use a small Flash Movie to store some data via Flash's Shared Memory Api or have a look at Google Gears.
    Maybe also consider, that every byte you store in the cookie have to be transmitted everytime you website makes a request to the server.

    0 讨论(0)
  • 2020-12-11 23:41

    Generally cookies have a max size of 4k so you could store quite a bit of data in there.

    Be careful with validating all information that lives cookies - all the information resides on a client browser and can easily be manipulated by users of the site at any time.

    You didn't say which platform you use. Spring Webflow does exactly the kind of form processing that you want: http://www.springsource.org/webflow

    Even if you don't use Java you could use some of the principles.

    Edit: One more drawback of big/complex persistent cookies is that you have to make sure that any new code you deploy is backwards compatible with all the cookies that are out in the wild.

    0 讨论(0)
  • 2020-12-11 23:43

    I would suggest storing the data in a session variable until you get to the final step rather than a cookie. I think this would be safer for your data as the user does not have direct access to the data, so you can validate as you go.

    0 讨论(0)
提交回复
热议问题