DEV Community

Cover image for JavaScript Local Storage Explained!

JavaScript Local Storage Explained!

Boateng Dickson on September 24, 2022

In the early days of the internet, you needed a server to store data. But nowadays, through LocalStorage, you can store data on browsers and applic...
Collapse
 
cicirello profile image
Vincent A. Cicirello

I use local storage for the site search page for my personal website to cache the search index. My site is a static website hosted on GitHub Pages. So without a backend, and without using some 3rd party service, search is run entirely in browser. Obviously can't feasibly do this for a very large site. But index for my site is just under 800 KB.

When using local storage for caching, you do need some mechanism to know when to use cached version and when to make a fresh request.

Collapse
 
kolja profile image
Kolja

RepoLink, please 😃

Collapse
 
cicirello profile image
Vincent A. Cicirello

The GitHub repo is: github.com/cicirello/cicirello.git...

The site itself is at: cicirello.org/

Collapse
 
alonedatascientist profile image
alonedatascientist

Good article! Very thorough.

Local Storage is super useful when you are in that intermediate sort of middle with learning and making projects. Maybe you need to save some data but perhaps you aren't trying to learn a database yet. Or maybe some simple prototyping. As long as you use it knowing its not secure and that eventually you'll have to give up the training wheels and head for a more robust data store I see it as a nice solution.

Collapse
 
fruntend profile image
fruntend

Сongratulations 🥳! Your article hit the top posts for the week - dev.to/fruntend/top-10-posts-for-f...
Keep it up 🫰

Collapse
 
rahulranjanme profile image
Rahul Ranjan

We use localStorage and its "storage" eventListener to share data from one tab to another.

Collapse
 
kosoko_daniel profile image
Oluwagbenga

Thank you

Collapse
 
yongchanghe profile image
Yongchang He

Thank you for sharing this!

Collapse
 
olsard profile image
olsard

Thank you

Collapse
 
andrewbaisden profile image
Andrew Baisden

Thats a super explanation.

Collapse
 
annie profile image
Annie

Hello, I love your article. Can I reprint and translate your article? I will include a link to the article.

Collapse
 
dboatengx profile image
Boateng Dickson

Hey, that's not a problem.

Collapse
 
dhruvjoshi9 profile image
Dhruv Joshi

was looking for something like this!!! thanks man!

Collapse
 
kosoko_daniel profile image
Oluwagbenga

Thank you