Should I use localStorage instead of cookies for a web application designed for mobile browsers?

I am creating a location-based web application that will work mainly on mobile browsers. It will be encoded with HTML5, javascript and PHP. I would like the user to be invited to log in as rarely as practical. I would like them to log in (via PHP) and then stay on for x time.

I know how to do this with cookies, but I experimented with HTML5 localStorage. If I use localStorage, I have to do all the validation using javascript and send it to PHP via Ajax. Since I am thinking how to do this, I am wondering if it is worth using localStorage. As far as I understand, it is more secure than cookies because data is not transmitted with every HTTP request and it cannot be accessed cross-domain. But do modern browsers, such as iOS and Android, not allow cross-domain access to cookies?

Am I just complicating myself using localStorage? What are the reasons for choosing localStorage over cookies in this case?

+4
source share
1 answer

Cookies and localStorage have two different ways of using, mainly cookies for reading on the server side, and localStorage for reading on the clientโ€™s slide.

If your client side needs this data, then yes, use localStorage (you save bandwidth by not sending cookies for every HTTP request [in the headers]). However, if you do not, just use cookies. By providing additional HTTP requests (via ajax) to send the server, cookies are a bit overloaded if everything you do has access to this data on the server side.

+7
source

Source: https://habr.com/ru/post/1343976/


All Articles