I put a multistep form's state in the URL so it can be shared, but the encoded JSON sometimes causes a 414 error. Is compression a practical fix, or should the state live somewhere else?
How can I share wizard state when the URL gets too long?
Answers
For a shareable wizard, save the state on the server and put a short identifier in the link. Opening the link can then load the saved state. You can save changes as the form progresses, or provide an explicit save and share action.
Decide whether the link should point to a fixed snapshot or a draft that keeps changing. Also consider expiry, cleanup, and who can read or edit it. An unguessable identifier helps, but it isn't a substitute for access controls when the data is restricted.
Reply to this answer
Base64 isn't compression. It usually makes the encoded data about a third larger. You could compress the JSON first and then use a URL-safe encoding, or shorten repeated keys and predefined values before compression.
That might work for small, bounded states, but it won't guarantee that a larger form fits. Test the resulting links through the browsers, servers, proxies, and sharing tools you actually use. A 2,000 character ceiling isn't a universal URL limit, and compression doesn't stop the contents from being exposed.
Reply to this answer
If sharing isn't needed for every draft, localStorage is a simpler place to keep the form between visits in the same browser. It won't make the state available to someone opening the link on another device, though. You could keep local drafts and use a server-backed link only when someone chooses to share.
Reply to this answer
One reason to move the form data out of the URL is privacy. URLs can end up in browser history, logs, and shared messages. Encoding or compressing the data doesn't make it secret, so check what the form can contain before putting any of it in a link.
Reply to this answer
POST is useful for sending the form state to the server without stuffing it into the request URL. It doesn't by itself give you a link that another person can open. For that, the server still needs to retain the state and return some kind of reference.
Reply to this answer
Add your answer
Answers are reviewed before publication.
a-voucher-for-friday:
A snapshot is useful if the recipient needs to see exactly what was shared, rather than whatever the draft contains later.