5 ms·
The only issue I have with Fetch is I can't get progress for up/downloading from it yet. Otherwise I prefer it over Ajax in every other way.
by RobertRoberts 4y ago
The only issue I have with Fetch is I can't get progress for up/downloading from it yet. Otherwise I prefer it over Ajax in every other way.
- ynniv 4y agoThis. Until fetch has all the features of xhr, what's the point of being pretty?
- tgv 4y agoThere are also fetch-like wrappers for xhr. Axios is a decent one, I think.
- mmis1000 4y agoI think fetch will never has all the features of `xhr`. At lease the sync `xhr` is not possible. The `promise` api don't even allow callback in `then()` to be called synchronized, let alone things like `fetch` that relies on it.
- TedDoesntTalk 4y agoIt’s also very difficult to save the received data to the browser as a file. It can be done with ugly hacks, but this should be supported natively in 2022. Background downloads are still a major PITA. Why?
- jjice 4y agoI don't have a lot of front end experience, but the way I've done it in the past was with <a download href="example.com/my/download/route"></a> and that always worked well for me. No idea if that would be helpful at all, I'm operating at a very surface level knowledge here.
- thunderbong 4y agoThat's the way to do if I want to just download a file. But the comments seem to be mentioning a scenario where they would like to download the file via Javascript.
- TedDoesntTalk 4y agoI’m talking about saving data received from an asynchronous fetch response as a file on oval file system.
- CornCobs 4y agoYou can do anything with the DOM in javascript - you could create an anchor node then download the file automatically via a.click()
- TedDoesntTalk 4y agoThat's how I do it now. And it's an ugly hack. Why is it not natively supported?
- rasz 4y agoWhat would you consider a native support? ability to drop files on user drives without prompt?
- TedDoesntTalk 4y agoNo, of course not. I’m not talking about the user experience. I’m talking about native support in the fetch API to take downloaded data and save it to a file. User experience might be the user being prompted for a location, etc, just like now when saving a file through a hyperlink download.
- la_fayette 4y agoSame for me, I just wonder how the standardization people could forget such a feature...
- qwtel 4y agoNo sure if I’m missing something, but you can tap directly into the readable stream of fetch which should be at least as good as progress events? I’ve used it here (https://sqliteviewer.app/ https://sqliteviewer.app/, click “load a sample”) and it works as expected.
- RobertRoberts 4y agoWell, I have something new to try... (just glanced at your project) If this works, why isn't this documented in an obvious manner on something like MDN?