3 ms·
Consider when you are visiting a page where you have been before, and you have received some identifier token. Using cookies, the browser automatically sends t
by goto11 7y ago
Consider when you are visiting a page where you have been before, and you have received some identifier token.
Using cookies, the browser automatically sends the identifier token along with the initial request, and the server can serve the initial response based on your identity.
With localStorage, the browser initially send an anonymous request to the server, the server then have to return some bootstrap JavaScript which reads the identity token from localStorage and then passes it to the server in the next request, and only then the server can respond based on your identity.
By any reasonable definition, the second approach is more complex, not to mention slower and more fragile.