Jump to content
Main menu
Main menu
move to sidebar
hide
Navigation
Main page
Recent changes
Random page
freem
Search
Search
Appearance
Create account
Log in
Personal tools
Create account
Log in
Pages for logged out editors
learn more
Contributions
Talk
Editing
Openai/6926aad9-faf0-8007-bcb8-9e64cd1f86b1
(section)
Add languages
Page
Discussion
English
Read
Edit
Edit source
View history
Tools
Tools
move to sidebar
hide
Actions
Read
Edit
Edit source
View history
General
What links here
Related changes
Special pages
Page information
Appearance
move to sidebar
hide
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
=== Assistant: 結論から言うと、10万文字のメモくらいなら localStorage で全然いけます 👍 === 結論から言うと、10万文字のメモくらいなら localStorage で全然いけます 👍 ==== - localStorage はブラウザにもよりますが、1オリジンあたりだいたい 5MB 前後(5〜10MB) が上限です。MDN Web Docs<ref>{{cite web|title=MDN Web Docs|url=https://developer.mozilla.org/en-US/docs/Web/API/Storage_API/Storage_quotas_and_eviction_criteria|publisher=MDN Web Docs|access-date=2025-11-27}}</ref> ==== * 文字列は内部的にだいたい 2バイト/1文字(UTF-16) と見ておくと安全です。 なので: * 10万文字 × 2バイト ≒ 200KB ≒ 0.2MB つまり、1メモ10万文字でも 5MB 制限に対して 1/25 くらい しか使いません。 アプリ全体で JSON のオーバーヘッドや他のメモを含めても、 * 10万文字メモを数個〜十数個 → まず問題なし * 10万文字メモを何十個もため込む → さすがに 5MB 近くなってくる可能性あり というイメージです。 ==== 1. 上限超えるとどうなる? localStorage.setItem したときに <code>QuotaExceededError</code> が投げられます。DEV Community<ref>{{cite web|title=DEV Community|url=https://dev.to/tommykw/testing-storage-limits-of-localstorage-and-sessionstorage-in-chrome-21ab|publisher=DEV Community|access-date=2025-11-27}}</ref> → try/catch で握って「容量オーバーです」みたいなメッセージを出すと安心。 ``<code>js try { localStorage.setItem(STORAGE_KEY, JSON.stringify(payload)); } catch (e) { if (e.name === "QuotaExceededError") { alert("保存容量の上限に達しました。古いメモを削除してください。"); } } </code>`` ==== # localStorage は同期処理 読み書きが同期なので、巨大な JSON を頻繁に書き換えるとメインスレッドを少しブロックします。 ・今の規模(数百KB〜数MB)なら大体問題ないですが、 ・オフラインノートアプリ級に巨大化させるなら IndexedDB に移行を検討したほうがいいです。web.dev<ref>{{cite web|title=web.dev|url=https://web.dev/articles/storage-for-the-web|publisher=web.dev|access-date=2025-11-27}}</ref> ==== - 10万文字のメモ単体なら localStorage で余裕。 ==== * そのアプリ構成(メモを KV で保存+一覧用の index)でも特に問題なし。 * もし「10万文字メモ × 100個」みたいな世界に行きそうなら、 - 「古いメモから削除」ロジックを入れる - もしくは IndexedDB へ移行 のどちらかを考えておくと安心です。 もしよければ、「今想定してる最大メモ数」がどれくらいか教えてもらえれば、それ前提で安全ラインをざっくり見積もったり、設計アドバイスもできます!
Summary:
Please note that all contributions to freem are considered to be released under the Creative Commons Attribution-ShareAlike 4.0 (see
Freem:Copyrights
for details). If you do not want your writing to be edited mercilessly and redistributed at will, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource.
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)