ตัวเลือกหลัก 3 อย่าง
| เทคโนโลยี | ขนาด | Persistence | รองรับ |
|---|---|---|---|
| localStorage | ~5-10MB | ถาวร (จนกว่าจะลบ) | ทุกเบราว์เซอร์สมัยใหม่ |
| sessionStorage | ~5-10MB | Session เท่านั้น (ปิด Tab หาย) | ทุกเบราว์เซอร์สมัยใหม่ |
| IndexedDB | หลายร้อย MB - GB | ถาวร | IE10+, ทุกเบราว์เซอร์ใหม่ |
ตัวอย่าง localStorage
<script>
if (localStorage.hits) {
localStorage.hits = Number(localStorage.hits) + 1;
} else {
localStorage.hits = 1;
}
document.write("Total Hits: " + localStorage.hits);
</script>
WebSQL - Deprecated, ไม่แนะนำใช้ใหม่
Cache API / Service Workers - สำหรับ Offline Caching ไม่ใช่ Database ทั่วไป