URL Shortener Simulator
Simulate URL shortening with localStorage-based link tracking.
关于此工具
Paste any long URL and get a simulated shortened link using a 6-character random code stored in your browser's localStorage. Optionally provide a custom alias instead of the auto-generated code. All your shortened links are listed below the input with their original URL, short code, creation date, and click count. Clicking a short link increments its counter so you can see simulated analytics. Note: these links only resolve within this browser tab — no real shortening service is used.
使用方法
- 1 Paste a long URL into the input field.
- 2 Optionally enter a custom alias; otherwise a 6-character code is generated.
- 3 Click Shorten to save the link and see the simulated short URL.
- 4 Click a short link to simulate a visit and increment its click counter.
- 5 Use the Delete button to remove any link from the list.
What a URL shortener actually does — and what this simulator demonstrates
A real URL shortener is a redirect database. When you shorten https://example.com/a/very/long/path?id=123, the service stores that long URL under a short code and hands you something like short.ly/aB3xY9. Later, when someone visits the short link, the service looks up the code, finds the original URL, and issues an HTTP 301 or 302 redirect that sends the browser onward. The short link is just a key; the destination lives in a table on a server. This tool is a simulator that reproduces that key-and-table model entirely inside your browser so you can see how the pieces fit — without operating a real redirect service. The links it produces look like https://boxtool.app/s/aB3xY9 but resolve only within this page; they will not work if you paste them into another browser or send them to a friend.
How the short code is generated
Each auto-generated code is 6 characters drawn at random from a 62-character alphabet: A–Z, a–z, and 0–9. That alphabet is what "base-62 encoding" refers to, and it is the industry-standard choice because it is URL-safe and case-sensitive. The math is why shorteners can stay tiny: six base-62 characters give 62^6 ≈ 56.8 billion distinct codes. Even a service handling millions of links has an astronomically small chance of two random codes colliding. This simulator still guards against it — before saving, it checks your existing links and regenerates the code (up to 20 tries) if it happens to clash.
Custom aliases and the trade-off they carry
Instead of a random code you can supply your own alias — useful for branded, memorable links like /s/spring-sale. The tool validates it against ^[a-zA-Z0-9_-]{1,20}$: letters, digits, hyphens, and underscores only, 1 to 20 characters. The trade-off is uniqueness. Random codes are essentially never taken; human-chosen words are. The simulator enforces this exactly as a real service would — if you try an alias that already exists in your saved list, it refuses and asks for a different one. That collision check is the reason every real shortener requires aliases to be globally unique.
A worked example
Paste https://en.wikipedia.org/wiki/Uniform_Resource_Locator and leave the alias blank. The tool first validates the URL by constructing a URL object and confirming the protocol is http: or https: — a bare string like example.com with no scheme is rejected. It then mints a code such as k7Qm2p, stores a record with the original URL, an ISO creation timestamp, and a click count of zero, and shows you https://boxtool.app/s/k7Qm2p. Click that short link in the list and the click counter ticks up to 1 — a stand-in for the analytics a real shortener records on every redirect. Each entry also offers Copy and Delete, and Clear All wipes the whole list.
Where the data lives
Everything is saved to your browser's localStorage under a single key, as JSON. There is no account, no server round-trip, and no tracking — which is precisely why the links cannot resolve elsewhere. localStorage is scoped to one origin in one browser, so your links vanish if you clear site data, switch browsers, or open the page in a private window. Treat this as a sandbox for understanding the mechanics, not as a place to store links you need to keep.
Genuine use cases for the simulator
- Teaching how redirects work. It makes the "code → lookup → destination" flow concrete for students learning web fundamentals.
- Prototyping a UI. Designers and developers can mock up a shortener dashboard — link list, click counts, custom aliases — before any backend exists.
- Understanding analytics. Watching the click counter increment shows exactly why shortened links can track engagement that a raw long URL cannot.
- Estimating namespace size. Experimenting with code length builds intuition for why six characters are enough for billions of links.
Common misconceptions
- "Shortening hides the destination." It obscures it visually, but the redirect target is fully recoverable. Real shorteners (and link-preview tools) expand them; never assume a short link is private.
- "Short links last forever." They live only as long as the service's database does. When a shortener shuts down, every link it ever made breaks — a phenomenon called link rot.
- "The code carries the URL." It does not. Unlike a QR code, which embeds its data, a short code is meaningless without the server that maps it. That dependency is the whole point of this demonstration — and the reason these particular links only work here.