0

Is there any theoretical reason why client-side JavaScript could not be spec'd to allow for direct access to POST or PUT contents without need for a server language to write it into client-side JavaScript first?

It would seem that this, besides avoiding an unnecessary dependency on server-side code where not needed, would allow for arbitrary length command-line type operations with side effects (such as changing localStorage) and could also open up what could be done with HTML served over the file:// protocol (assuming the POST to the file:// originated from a trusted context).

  • Servers don't generally send the request data back to the client. What you are proposing would require the server to send the entire request back every time. This doesn't seem reasonable. If you want the client to have access to some data that originated on the client, why does the server need to be involved at all? – Hey Jan 25 '15 at 6:55
  • When someone tries refreshing a page with POST, because these requests are not supposed to be cached, it should be a fresh copy, no? The server doesn't need to be involved, except that what other API can one use to supply variable contents to a local or remote resource which isn't subject to URL length limits (and its idempotent requirements)? – Brett Zamir Jan 25 '15 at 7:00
  • I guess you are saying that some other new but roughly equivalent HTTP methods would be more suitable because it wouldn't need to be sent to the server? – Brett Zamir Jan 25 '15 at 7:11
  • When you make a request in the usual way (POST or otherwise), the browser navigates, destroying the state of any scripts. Since the server doesn't send your request back to you, there's no way the request body can be available to the script. For this to work you'd need some special new feature that captures the request when you send it and allows it to persist until the execution environment is rebuilt. But what if you uploaded a large movie, do you want that data hanging around in memory? What if you posted something from one domain to another? This sounds like more trouble than it's worth. – Hey Jan 25 '15 at 7:13
  • If this relies on new HTTP methods (or some other meta process), it wouldn't be an issue except when the user used these new methods. I envision an example UI being a command line in one's browser that one can use to submit commands which are picked up by the client-side script. – Brett Zamir Jan 25 '15 at 7:22

Your Answer

By clicking "Post Your Answer", you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.