开发者

Should I use localStorage instead of cookies for web app targeted at mobile browsers?

I'm building a location-based web app that will run primarily on mobile browsers. It will be coded with HTML5, javascript, and PHP. I'd like the user to have to be prompted to login as infrequently as practical. I'd like them to login (via PHP) and then stayed logged in for x amount of time.

I know how to do this with cookies, but I've been experimenting with HTML5 localStorage. If I use localStorage, I have to do all the validation with javascript and send it to PHP via Ajax. As I'm thinking through how to get this done, I wonder if using localStorage is really worth it. From what I understand, it's more secure than cookies because the data is not transmitted with every HTTP request, and it can't be accessed cross-domain. But don't modern开发者_如何学C browsers, like iOS and Android, prevent cross-domain access to cookies?

Am I just making it harder on myself by using localStorage? What are the reasons to choose localStorage over cookies in a case like this?


Cookies and localStorage have two different uses, mainly cookies are for reading by the server side, and localStorage is for reading by the client slide.

If your client side needs this data, then yes, use localStorage(you'll save bandwidth by not sending the cookies for every HTTP request[in the headers]). However if you are not, then just stick to using cookies. Making additional HTTP requests(via ajax) to send the server the cookies is a little overkill if all you are doing is having the server side access this data.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜