A small JavaScript library for reading, writing, and removing browser cookies with broad browser support and no runtime dependencies.
Overview
JavaScript Cookie offers a compact API for managing HTTP cookies entirely on the client. It focuses on straightforward get, set, and remove operations while supporting modern cookie attributes that browsers expect.
The library ships without dependencies and can load as an ES module or through AMD and CommonJS bundlers. You can override default encoding and decoding when you need custom converters, and TypeScript type declarations are available for typed projects.
Cookie options documented in the project include domain visibility, secure transmission over HTTPS, partitioned storage alongside secure cookies, and SameSite behavior for cross-site requests. Documentation also notes Internet Explorer quirks and warns against letting untrusted input control cookie attributes to reduce XSS risk.
For applications that also set or read cookies on the server, separate server integration guidance is maintained outside the core browser API.
Key features
- Client-side get, set, and remove
- Wide browser compatibility
- ES, AMD, and CommonJS modules
- Custom encoding and decoding hooks
- TypeScript declarations
- Secure, SameSite, and partitioned options
- No package dependencies
- Documented domain and path behavior
Use cases
- Persist user preferences in the browser
- Store short-lived session tokens on the client
- Tune cookie security attributes for HTTPS sites
- Share cookie helpers across bundled front-end code