Cookie Library: Modern Alternatives

The Perl Cookie Library handled HTTP cookies. Today, browsers offer multiple storage APIs and frameworks provide built-in session management.

Browser Storage

Browser Storage APIs

localStorage

Persistent key-value storage. Data survives browser restarts. ~5MB capacity. Perfect for user preferences and settings.

Built-in ~5MB Persistent
localStorage.setItem('theme', 'dark');
const theme = localStorage.getItem('theme');
sessionStorage

Session-only storage. Cleared when tab closes. Same API as localStorage. Good for temporary form data.

Built-in ~5MB Session only
IndexedDB

Client-side database for large amounts of structured data. Supports indexes, transactions, and complex queries. Async API.

Built-in Large storage Structured data
Cookies (document.cookie)

Traditional cookie API, still needed for server-side session management. HttpOnly and Secure flags for security.

Built-in ~4KB per cookie Server-accessible

JavaScript Cookie Libraries

js-cookie

Simple, lightweight JavaScript API for cookies. Works with all browsers, no dependencies. Encoding handled automatically.

Free MIT License ~800 bytes
universal-cookie

Universal cookies for JavaScript. Works on server and client. React integration available. TypeScript support.

Free MIT License Universal (SSR)

Modern Session Management

JSON Web Tokens (JWT)

Industry standard for secure authentication. Stateless, self-contained tokens. Used by OAuth 2.0 and modern APIs.

Open Standard Stateless API-friendly
Framework Session Management

Modern frameworks (Express, Laravel, Django, Rails) include solid session handling with security features built-in.

Express: express-session PHP: $_SESSION Django: sessions

Cookie Consent & Privacy

CookieYes

Cookie consent solution for GDPR, CCPA, LGPD compliance. Auto-detects cookies, blocks before consent, generates policy.

Free tier GDPR compliant
Cookie Consent (Open Source)

Lightweight, GDPR-compliant cookie consent manager. No dependencies, customizable, self-hosted.

Free / Open Source MIT License ~20KB

Storage Comparison

Feature Cookies localStorage sessionStorage
Capacity~4KB~5MB~5MB
ExpirationConfigurableNeverTab close
Server accessYesNoNo
Sent with requestsYesNoNo
API simplicityComplexSimpleSimple
Privacy lawsRegulatedLess regulatedLess regulated

Recommendation

Simple preferences: localStorage

Server sessions: Framework built-in

API auth: JWT tokens

Cookie helper: js-cookie

Privacy Laws

  • GDPR (Europe)
  • CCPA (California)
  • LGPD (Brazil)
  • ePrivacy Directive
  • Cookie consent required
All Examples Cookie Library Overview