Chuyển đến nội dung
Skillpedia
Website và giao diện (frontend)75k · #3084

web-storage

Skill này làm gì

Skill này kiểm tra cách trang web dùng bộ nhớ trình duyệt và làm cho code đó an toàn trước lỗi. Nó dành cho lập trình viên có ứng dụng lưu dữ liệu trong trình duyệt.

Khi nào nên dùng

  • ✓Khi code đọc hoặc ghi localStorage mà không có xử lý lỗi.
  • ✓Khi ứng dụng lưu đối tượng vào bộ nhớ mà không kiểm tra khi đọc lại.
  • ✓Khi dữ liệu nhạy cảm như token đăng nhập được giữ trong local storage của trình duyệt.

Liên kết skill

https://github.com/thedaviddias/Front-End-Checklist/blob/main/skills/web-storage/SKILL.md

Sao chép rồi dán vào AI của bạn (Claude, ChatGPT hoặc Cursor) và nhờ nó làm theo hướng dẫn.

Cách dùng

Cách dễ nhất: sao chép tin nhắn và dán vào AI của bạn. AI sẽ đọc skill và làm theo hướng dẫn.

Tin nhắn có sẵn để dán

Hãy dùng skill này để giúp tôi: https://github.com/thedaviddias/Front-End-Checklist/blob/main/skills/web-storage/SKILL.md Đọc tệp SKILL.md tại liên kết đó và làm theo hướng dẫn cho việc của tôi.
Bạn muốn AI tự tìm những skill như thế này?Cài MCP Skillpedia miễn phí: chỉ một dòng, và AI sẽ tìm trong 15.000+ skill trước mỗi việc.Cài đặt trong 1 phút →

Ví dụ cách nhờ AI

“Ứng dụng của tôi bị sập khi lưu cài đặt ở chế độ riêng tư. Bạn có thể làm code lưu trữ an toàn không?”

5 skill mới mỗi tuần. Đọc chỉ 1 phút.

Cách hoạt động

Agent bao các thao tác đọc và ghi bộ nhớ trong xử lý lỗi và kiểm tra dữ liệu đã tuần tự hóa khi tải lại. Nó cũng đánh dấu dữ liệu nhạy cảm không nên giữ trong bộ nhớ trình duyệt.

Nội dung kỹ thuật (SKILL.md gốc)

Lấy nguyên văn từ GitHub, do tác giả viết bằng tiếng Anh.

Use Web Storage API safely

localStorage and sessionStorage have a 5–10 MB quota per origin, and any write can throw a QuotaExceededError. Private browsing modes in some browsers disable storage entirely and throw on all writes. Applications that don't handle these errors crash silently, leaving users unable to use the app.

Quick Reference

  • Always wrap localStorage access in try/catch — storage can be full or disabled
  • Serialize objects with JSON.stringify and validate on read with JSON.parse
  • Never store sensitive data (tokens, passwords) in localStorage — use httpOnly cookies
  • Use sessionStorage for tab-scoped data that shouldn't persist

Check

Find all localStorage and sessionStorage accesses in this file. Check for missing try/catch, unhandled JSON parsing, and any storage of sensitive data.

Fix

Add try/catch error handling to all Web Storage operations and ensure all object values are properly serialized and deserialized.

Explain

Explain the Web Storage API, its limitations, when to use localStorage vs sessionStorage, and what data should never be stored there.

Code Review

Review scripts, client components, and browser execution paths related to Use Web Storage API safely. Flag exact imports, event handlers, runtime side effects, or blocking operations that violate the rule, and state how the change should be verified in the browser.


For full implementation details, code examples, and framework-specific guidance, see references/rule.md.

Rule page: https://frontendchecklist.io/rules/javascript/web-storage

Câu hỏi thường gặp

Tại sao bộ nhớ lại gây sập?

Bộ nhớ có giới hạn kích thước, và một số chế độ duyệt riêng tư tắt nó, nên các thao tác ghi có thể ném lỗi mà ứng dụng phải xử lý.

Khi nào sessionStorage là lựa chọn tốt hơn?

Skill gợi ý sessionStorage cho dữ liệu chỉ cần tồn tại trong một tab trình duyệt.

Điều gì không bao giờ nên đặt trong localStorage?

Token và mật khẩu. Skill khuyên dùng cookie httpOnly cho những thứ đó.

Chi tiết

Mô tả gốc của tác giả

Use when reviewing scripts, client components, bundles, or runtime behavior related to Use Web Storage API safely. Inspect both source code and the browser execution path so fixes target the real bottleneck or bug.

repo: thedaviddias/Front-End-Checklist

Độ phổ biến

Sao GitHub
75k
Vị trí xếp hạng
#3084
Giấy phép
MIT
Cập nhật
31/10/2026

Skill này có hữu ích không?

0

Đăng nhập để bình chọn.

Bình luận

  • …

Thêm skill từ kho mã này

Skill tương tự