Closed Bug 729109 Opened 13 years ago Closed 7 years ago

Make sure synchronous XHR examples don't appear on MDN

Categories

(Developer Documentation Graveyard :: API: DOM, defect)

defect
Not set
normal

Tracking

(Not tracked)

RESOLVED FIXED

People

(Reporter: hsivonen, Unassigned)

Details

(Whiteboard: [bcp47] u=webdev p=0 c=DOM)

Synchronous XMLHttpRequest is among the most painful parts of the Web platform. Even though its existence is kinda Mozilla's fault (for cloning even the bad parts of Microsoft's initial XHR) and even though we can't completely remove support, we shouldn't suggest to Web developers that it's something they might use. When Web developers use synchronous XHR, they tickle bad bugs in Gecko and even when they don't tickle bugs, synchronous XHR is bad for the user experience, since it locks up the page.
Sheppy, Janet, Jean-Yves, can any of you work with Henri to decide if and how such advice might be worked into MDN docs?
Just because it's bad doesn't necessarily mean it shouldn't be documented. But we can strongly de-emphasize it. What I'd probably do is change the "Synchronous and asynchronous requests" section to simply mention the existence of synchronous requests, but that they're a very bad idea, then move the docs for synchronous requests down to the very end instead of presenting them first.
Note, sync XHR is bad in window context. Sync APIs are ok in workers.
"8.4% of all hangs in IE9 in the past month are caused by XMLHttpRequest objects blocking the UI thread with a synchronous request. That’s a huge number!" http://blogs.msdn.com/b/wer/archive/2011/08/03/why-you-should-use-xmlhttprequest-asynchronously.aspx We should have strongly worded advice to *never* use it other than in workers. I think we should also mention that JSON-RPC is implemented using sync XHR and thus you shouldn't use that on the UI thread either. (bug 709746) I think we should also edit the JSON-RPC wikipedia page to warn people of this footgun. https://en.wikipedia.org/wiki/JSON-RPC
Also, I would like to see this advice directly in the spec too: http://www.w3.org/TR/XMLHttpRequest/#the-open-method
(In reply to Eric Shepherd [:sheppy] from comment #2) > Just because it's bad doesn't necessarily mean it shouldn't be documented. It's OK and honest to say that it exists (in the doc for the open() method). However, I think the doc should say never to use it outside Workers. I think all examples that use XHR outside Workers should be async--preferably so that the third argument to open() is omitted to avoid drawing attention to the fact that passing a different boolean is a possibility.
Component: Documentation Requests → Documentation
We've done a good bit of work on this over the last year or so, and I just now swapped sync and async so the latter is listed first in the docs, so I'm marking this fixed.
Status: NEW → RESOLVED
Closed: 13 years ago
Resolution: --- → FIXED
The example in "Handling responses" still use sync XHR: https://developer.mozilla.org/en-US/docs/DOM/XMLHttpRequest/Using_XMLHttpRequest The chosen example and the text after it: "There are some situations where the contents of a remote response from an XMLHttpRequest may not be handled as easily as the case above." strongly suggests that sync XHR is the preferred way and there is no mention of any problems with it whatsoever. :-( The sync examples needs to be removed ASAP (there's two more further down). It would be nice to have a simple boiler plate async example in its place. Again, in the API documentation there's no mention of any problems with using sync XHR. It should have STRONGLY worded text that sync XHR should be avoided like the plague it is. https://developer.mozilla.org/en-US/docs/DOM/XMLHttpRequest I would prefer if the Using_XMLHttpRequest page didn't even mention sync XHR. As Henri said, we can simply omit the third arg in the examples. We already link "open()" to the API page for anyone wanting further info.
Status: RESOLVED → REOPENED
Resolution: FIXED → ---
Component: Documentation → General
Product: Mozilla Developer Network → Developer Documentation
Component: General → DOM
Whiteboard: u=webdev p=0
Whiteboard: u=webdev p=0 → [bcp47] u=webdev p=0 c=DOM
There is now https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/Using_XMLHttpRequest#Types_of_requests and https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/Synchronous_and_Asynchronous_Requests which talk about async and sync request types. Please open a new bug if there are still specific problems with the current XHR MDN docs.
Status: REOPENED → RESOLVED
Closed: 13 years ago7 years ago
Resolution: --- → FIXED
(In reply to Florian Scholz [:fscholz] (MDN) from comment #9) > There is now > https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/ > Using_XMLHttpRequest#Types_of_requests and > https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/ > Synchronous_and_Asynchronous_Requests which talk about async and sync > request types. Please open a new bug if there are still specific problems > with the current XHR MDN docs. I changed "In general, you should rarely if ever use synchronous requests." to "Do not use synchronous requests outside Web Workers." in order to make this bug FIXED.
Status: RESOLVED → REOPENED
Resolution: FIXED → ---
I'm not sure you meant to reopen this. If you did, please clarify what else is needed.
Status: REOPENED → RESOLVED
Closed: 7 years ago7 years ago
Resolution: --- → FIXED
Sorry, I first put the Bugzilla form to reopened state, but before submitting, I went ahead and edited the wiki myself instead.
You need to log in before you can comment on or make changes to this bug.