본문 바로가기
Programming/HTML

localStorage와 sessionStorage 차이점(알고 사용하자)

by 배고프당 2019. 8. 22.
728x90

일단 생각나는대로 정리해보면....


1. localStorage

 1) 사용자 세션 데이터 유지할수 있다

 2) 브라우저 닫았다가 다시 열었을 때도 지속된다.

 3) 탭을 여러개 열어도 공유된다.

 4) 명시적으로 삭제될때까지 지속된다.

 5) 변경 사항은 저장되어 현재 및 향후 사이트 방문 시 사용할 수 있다.


* 정리 :  사용자가 브라우저 창을 닫았을 때 데이터는 삭제되지 않으며, 일, 주, 월 및 연도에 사용할 수있는 만료 날짜없이 사용자 정보 데이터를 저장한다.


1
2
3
4
5
6
7
8
9
//Set the value in a local storage object
localStorage.setItem('name''sanghoone');
 
//Set the value in a local storage object
localStorage.getItem('name');
 
//Delete the value from local storage object
localStorage.removeItem('name'); //Delete specifice obeject from local storege
localStorage.clear(); //Delete all from local storege
cs

2. sessionStorage

 1) 브라우저 세션 기간 동안 만 사용할 수 있으며 탭이나 창을 닫을 때 삭제된다.

 2) 새로고침을 해도 유지된다.

 3) 변경 된 사항은 현재 페이지에서 닫힐 때까지 저장되어 사용할 수 있다.

 4) 탭이 닫히면 저장된 데이터가 삭제 된다.



1
2
3
4
5
6
7
8
9
//Set the value in a session storage object
sessionStorage.setItem('name''sanghoone');
 
//Set the value in a session storage object
sessionStorage.getItem('name');
 
//Delete the value from sessionstorage object
sessionStorage.removeItem('name'); //Delete specifice obeject from session storege
sessionStorage.clear(); //Delete all from session storege
cs




localStorage에 값을 입력하고 새 탭을 열어보면 localStorage가 공유되는 것을 확인 할 수 있다.






위 특성들에 맞게 본인이 원하는 속성을 활용하면 될 거 같다.







728x90

'Programming > HTML' 카테고리의 다른 글

모바일 웹 meta 태그 설정  (0) 2019.04.02

댓글