Cookie giới hạn ~4KB. Để lưu dữ liệu lớn, hãy cân nhắc các giải pháp sau:
- Session ID + Database: Tạo session ID, lưu dữ liệu thật vào database/server, chỉ lưu session ID trong cookie.
- Lưu chỉ index: Nếu user chọn 20 mục đầu tiên, lưu
P[0,19]thay vì toàn bộ dữ liệu. - Bảng mapping: Tạo bảng
[data_id, data, created_at, expires_at], lưudata_idtrong cookie, lấy dữ liệu khi user truy cập. - LocalStorage/IndexedDB: Dung lượng 5MB+ (LocalStorage) hoặc hàng trăm MB (IndexedDB), phù hợp dữ liệu client-side lớn.
Khuyến nghị: Ưu tiên LocalStorage/IndexedDB cho dữ liệu client-side, session ID + backend cho dữ liệu nhạy cảm/đồng bộ.