Recommend localStorage, sessionStorage, or a cookie for a browser storage use case, weighing data lifetime against server visibility, with code to set and read it.
You are a web development instructor who answers "should I use localStorage or a cookie" with a real decision every time, because the three options genuinely differ on two questions that matter, how long the data needs to survive and whether the server needs to automatically see it on every request, and a table of differences with no decision made for the actual use case just pushes the choice back onto the student. My use case is [USE_CASE], described in plain English, such as keeping someone logged in across browser restarts, remembering a shopping cart only for the current tab, or storing a theme preference that a server-rendered page needs to know about before it even sends the HTML back. If I left that blank, ask me to describe what you're actually trying to store instead of comparing all three options with no use case to apply them to. Based specifically on [USE_CASE], ask two questions out loud and answer them from what I described: does this data need to survive closing the browser and coming back later, or only the current tab session, and does the server need to receive this data automatically with every request, or does the browser only need to read and write it locally. From those two answers, recommend exactly one of localStorage, for data that should persist and never needs to be sent to the server automatically, sessionStorage, for data scoped to the current tab that clears when it closes, or a cookie, for data the server needs to see attached to every request, and state plainly why the other two would be the wrong fit for this specific case. Write the actual code to set and then read back the data described in [USE_CASE] using the recommended option, with a plain-language comment on each line. State the realistic storage size limit for the recommended option, roughly five to ten megabytes for localStorage and sessionStorage, roughly four kilobytes for a single cookie, and whether that limit could realistically matter for [USE_CASE] as described. My depth is [DEPTH:select:just the recommendation,also explain the security tradeoff]. If I chose the second option, explain briefly that cookies get sent automatically with every matching request, which is exactly what makes them the right fit for server-visible data but also means anything sensitive stored there needs the `HttpOnly` and `Secure` flags to limit how it can be accessed and transmitted, while localStorage and sessionStorage are readable by any JavaScript running on the page, which matters if the page ever loads a third-party script. Close by asking whether [USE_CASE] actually has a second piece of data with different lifetime needs than the first, since a real app very often needs more than one of these three storage options at once rather than picking a single one for everything.
Use this prompt anywhere
10,000+ expert prompts for ChatGPT, Claude, Gemini, and wherever you use AI.
Get Early AccessShould I use localStorage or a cookie deserves a real answer, not a table of differences. The three browser storage options split on two questions, does the data need to survive closing the browser, and does the server need to automatically see it on every request, and once those two questions get answered for an actual use case, the right option stops being a guess.
This tool answers both questions from your description, then recommends one option, localStorage for data that should persist and never needs to reach the server automatically, sessionStorage for data scoped to the current tab, or a cookie for data the server needs on every request, explaining why the other two are the wrong fit. It writes the actual code to set and read the data, and states the realistic size limit, roughly four kilobytes for a cookie versus five to ten megabytes for the other two.
Set [DEPTH] to also learn the security tradeoff behind each option, including why sensitive cookie data needs specific flags. Run it in the Dock Editor to build a set of use cases decided, pair with the api request explainer for how a cookie travels with a request, or the data storage units explainer for the kilobyte and megabyte math behind the size limits.
Paste it into the Dock Editor, or into ChatGPT, Claude, or Gemini, then set [USE_CASE] to the actual data you're trying to store in the browser, in plain English, not an abstract scenario.
Get the two questions that actually decide this, how long the data needs to survive and whether the server needs it automatically, answered from your description.
Get exactly one of localStorage, sessionStorage, or a cookie recommended, with a plain explanation of why the other two would be the wrong fit.
Get real code that sets and then reads back your described data using the recommended storage option, with a plain-language comment on each line.
Set [DEPTH] to learn why cookies sent automatically need specific security flags, and why the other two options are readable by any script on the page.
Get a real recommendation between localStorage, sessionStorage, and cookies for your actual feature instead of guessing or copying whichever one a tutorial used.
Describe what you stored and where, and find out whether sessionStorage's tab-only lifetime, not a bug, is why the data vanished after closing the tab.
Get the right storage option recommended for keeping a user logged in, with the actual code and the security tradeoff explained before it ships.
Confirm that a cookie, not localStorage, is the right fit when the server itself needs to read a piece of client-side data on every request.
Discover more prompts that could help with your workflow.
Build a small working program that calls a real public API, with the request, response, and API key setup explained step by step.
Explain a core functional programming idea, such as pure functions or immutability, with a broken code example and its fixed version shown side by side.
Explain a built-in math function, square root, power, absolute value, or rounding, covering math and syntax, then generate practice calls to predict before revealing results.
10,000+ expert-curated prompts for ChatGPT, Claude, Gemini, and wherever you use AI. Our extension helps any prompt deliver better results.