스토리지 API
스토리지 객체
Web Storage API의 Storage 개체는 특정 도메인에 대한 세션 저장소 또는 로컬 저장소에 대한 액세스를 제공합니다. 이를 통해 저장된 데이터 항목을 읽고, 추가하고, 수정하고, 삭제할 수 있습니다.
저장소 개체 속성 및 메서드
Property/Method | Description |
---|---|
key(n) | Returns the name of the nth key in the storage |
length | Returns the number of data items stored in the Storage object |
getItem(keyname) | Returns the value of the specified key name |
setItem(keyname, value) | Adds that key to the storage, or update that key's value if it already exists |
removeItem(keyname) | Removes that key from the storage |
clear() | Empty all key out of the storage |
Web Storage API 관련 페이지
Property | Description |
---|---|
window.localStorage | Allows to save key/value pairs in a web browser. Stores the data with no expiration date |
window.sessionStorage | Allows to save key/value pairs in a web browser. Stores the data for one session |
쿠키 대 로컬 저장소
쿠키는 클라이언트-서버(브라우저-서버) 애플리케이션을 위한 것입니다.
로컬 스토리지는 클라이언트(브라우저) 애플리케이션을 위한 것입니다.
쿠키는 웹사이트와 연결됩니다. 데이터가 클라이언트용인 경우 모든 HTTP 헤더에서 쿠키를 보내는 것은 대역폭의 허리입니다.
일부 사용자는 브라우저에서 일반적으로 쿠키를 비활성화합니다.
쿠키의 크기 제한은 4KB입니다. 로컬 저장소는 도메인당 5MB로 제한됩니다.
쿠키에는 만료일이 있습니다. 로컬 스토리지에는 없습니다.
브라우저 지원
Storage API
모든 브라우저에서 지원됩니다:
Chrome | IE | Edge | Firefox | Safari | Opera |
Yes | 8-11 | Yes | Yes | Yes | Yes |