S
S
seredaes2015-10-01 15:18:57
JavaScript
seredaes, 2015-10-01 15:18:57

"localstorage" or cookie?

I want to use localStorage in my work.
Who used what reefs are?
I know that cookies can be disabled, but can this be disabled somehow?

Answer the question

In order to leave comments, you need to log in

6 answer(s)
D
Dmitry Korolev, 2015-10-01
@seredaes

In fact, everything is simple. Cookies are for the server, localstorage is for the client. If the information you're going to store is only needed on the client, there's no point in running cookies back and forth on every request to the server. If some information is constantly needed by the server, use cookies.
In addition, a cookie of 4kb is allocated, on localStorage - 5mb.
There are no pitfalls, if there is no need to support the old ones - use it safely. caniuse.com/#search=localstorage
As for disabling: the user can prevent localStorage from being used proactively. In practice, I have not come across this, I think that they purposefully do this even less often than disabling cookies.

T
triton, 2015-10-01
@triton

I’ll add to what has already been written above:
Cookies can be set on a second-level domain and it will be available in subdomains, and localStorage is tied only to the full domain.
Also note that safari has a special mode where any attempt to write something to localStorage will result in a script error. This mode is not often used, so it is better to add handling for this error.
So, use what works best.

I
Ivanq, 2015-10-01
@Ivanq

Pros:
localStorage cannot be disabled.
localStorage will live forever unless you or the user deletes it (or the computer burns down) ) .
Using localStorage is easier

document.cookie = "a=b"; // Добавляем куки
document.cookie = "a="; // Удаляем куки
// ??? Скачиваем функцию для получения куки

localStorage.addItem("a", "b");
localStorage.removeItem("a");
localStorage.getItem("a");
// или
localStorage.a;

Cons:
Works like a cookie, but you can't set it from the server.
For reception from the server it is necessary to transfer in request.

L
LittleFatNinja, 2015-10-01
@LittleFatNinja

everything that is stored by the user, the user can disable

I
Ilya Bobkov, 2015-10-01
@heksen

there are no stones at localstorage

K
keslo, 2015-10-01
@keslo

local storage

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question