DEV Community

Cover image for Using the Local Storage

Using the Local Storage

Sarah Chima on June 05, 2019

This article discusses what the local storage is and JavaScript methods that we can use to manipulate it. I have always known about the local stor...
Collapse
 
nikolicstjepan profile image
Stjepan

So if I got this right - localStorage is a like cookies except expire part (ls lasts until cleared) and you can store more data in it?

Thanks for the article, it is super useful!

p.s. I relay like design of your Note App!

Collapse
 
marcel_cremer profile image
Marcel Cremer

No it's not - especially not in terms of security (because LocalStorage has no security model).

See also Please Stop Using Local Storage which shows some of the downsides.

Collapse
 
sarah_chima profile image
Sarah Chima

Thanks for reading. I guess your question has been answered by Marcel and Lars.

Collapse
 
larsklopstra profile image
Lars Klopstra ⚡

It's also limited to the client for the specified site, servers and other sites can not access it

Collapse
 
ybogomolov profile image
Yuriy Bogomolov

Sorry, but this article could be a bit misleading to newbie devs. It doesn't describe that accessing localStorage could result in a SecurityError (thus robust web apps should wrap LS access in a try-catch or similar mechanism), and the size of LS is not always equal to 5 MiB (on older Androids it is smaller, for example).

It would be fair to provide a link to MDN: developer.mozilla.org/en-US/docs/W..., which describes LS in greater details.

Collapse
 
adam_cyclones profile image
Adam Crockett 🌀

Session storage would be a better alternative also or no client side storage at all, even better, for legal and security reasons.

Collapse
 
vigyanhoon profile image
Sanjay Pandey

Short and simple, thats how all articles should be. Alas people think more jargons they use, more people see them as geeks.

Collapse
 
sarah_chima profile image
Sarah Chima

Thank you.

Collapse
 
adam_cyclones profile image
Adam Crockett 🌀

It is a good article, just the subject is a little controversial.

Collapse
 
wendell_adriel profile image
Wendell Adriel

Great article, simple and right to the point.
I had some cases in some projects at my company that I needed to extend how to work with the Local Storage, then I created these two packages here:

github.com/WendellAdriel/time-storage
github.com/WendellAdriel/counted-s...

Depending on which kind of app we're working with, Local Storage can be a good friend!!!

Collapse
 
entioentio profile image
entio

If you just wanna be fine, dandy and secure wherever possible, use this github.com/localForage/localForage

API is pretty similar to localStorage but it uses IndexedDB or WebSQL where possible to allow quick and easy access.

Collapse
 
dago_djanaya profile image
dago

Sara thanks, i really enjoy it your article,n use it before finished it, but i crash with a big wall when i go ahead n try to understand your NoteApp code, im a newbe that happen a lot, kinda like: wtf there is no "package.json" here, how do i install this thing... u know what i mean 😁.

Collapse
 
aibee profile image
Iboro

Lovely piece, need to start using this. Would've liked to see how you implemented your state object though.

Collapse
 
ipurak profile image
Rungrot Suptan

Thanks!! Great article!

Collapse
 
sarah_chima profile image
Sarah Chima

Thank you for reading.

Collapse
 
kyleljohnson profile image
Kyle Johnson

Arguably the most under used thing in web development. Great article!

Collapse
 
sarah_chima profile image
Sarah Chima

Thank you.

Collapse
 
10secondsofcode profile image
Elango Sundar

Detailed explanation about local storage...thanks..keep it up.

Collapse
 
sarah_chima profile image
Sarah Chima

Thanks for reading it.

Collapse
 
efleurine profile image
Emmanuel

Thanks for the details explanation

Collapse
 
sarah_chima profile image
Sarah Chima

I'm glad you like it.

Collapse
 
narthcodes profile image
dumtochukwu

wow i love the article

Collapse
 
jsgoose profile image
Jonathan Sexton

Hi Sarah! I loved your article and would like to include it in my June Newsletter that I send out. I'll put a link to this article and attribute you if you're alright with that?

Collapse
 
sarah_chima profile image
Sarah Chima

Hi Jonathan. Thanks for reading my article. I'm glad you like it. It will be my pleasure for my article to be included in your newsletter.

Collapse
 
jsgoose profile image
Jonathan Sexton

Thank you so very much Sarah! I really appreciate that!

I look forward to your future work!

Collapse
 
adam_cyclones profile image
Adam Crockett 🌀

Indexedb that is a better alternative.

Collapse
 
iamakomvictory profile image
iamakomvictory

Hi Sarah! I loved your article and would like to make acquaintance to connect on any of your social media may be LinkedIn :)

Collapse
 
robertahisle profile image
RobertaHisle

What should we store in local storage? Dua to convince someone for something