Localstorage Vs Cookies - Performance

Since cookies are server-side and Localstorage are client-side , which is the fastest user to download? (link Local Storage vs Cookies )

I assume that if the client machine is slow, are cookies faster? Or does it make no difference?

I use both localstorage and cookies for the project, and both are retrieved using jQuery. This means jquery must load, then the data is retrieved.

How can I do it faster? I don’t know how both work. For example, some say that Cookies are retrieved after HTML tries to load style and js files, while others say when the DOM is ready.

Does anyone know the exact information that is faster for the user to retrieve ?

thanks

+6
source share
3 answers

Since cookies are server-side and Localstorage are client-side, what is the fastest for a user to receive?

You start with the wrong assumption. Cookies are stored on the client side. Both localStorage and cookies are stored on the client side.

However, the difference, and that cookies can be set, is managed by the server. localStorage only works on the client side.

I assume that if the client machine is slow, are cookies faster? Or does it make no distinction [sic]?

They are such an easy operation. I would not worry about speed.

Productivity between them is not a factor for its choice. These are your needs.

Cookies:

  • For a long time they worked in browsers. Every modern, but not very modern browser to support the browser.
  • Access to and management of the server.
  • Usually limited to a few kilobytes, depending on the browser.

LocalStorage:

  • This is a relatively new concept. Not all browsers support it. For example, IE 6, 7, and you're out of luck.
  • Not available from server side. You can make an AJAX call to the server with the data stored in localStorage.
  • You have a W3C recommendation of saving 5 MB.

How can I do it faster?

I don’t think anyone can introduce a performance issue right away. Other issues, such as waiting for the DOM to be ready while waiting for script files to load; etc. may slow down.

+26
source

Cookies and LocalStorage are stored locally on the client. There should be no noticeable difference in how quickly you can read them.

Cookies have the disadvantage that they are sent to and from the server using HTTP requests and responses. This can increase page size by increasing page load time.

If you use jQuery to read cookies / LocalStorage, the browser will have to wait for the jQuery script to load if it is not in the browser cache.

+1
source

If I was really misled, both cookies and localStorage will be on the client side.

I would look at How to set / delete a cookie using jQuery?

And there is a pretty convenient jQuery plugin at: http://plugins.jquery.com/project/Cookie - I use this all the time.

-3
source

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


All Articles