After some experimenting, it seems both Chrome and Safari are able to download a file of 2GB just fine when revoking right after clicking an element. And Firefox was able to download a file of 600MB before the browser started grinding to a halt.
This is what I used to download large files:
const a = document.createElement('a');
const buffer = new ArrayBuffer(2_000_000_000);
const view = new Uint8Array(buffer);
for(let i=0; i<view.length; i++) {
view[i] = 255;
}
a.href = URL.createObjectURL(new Blob([buffer]));
a.download = 'some.dat';
a.click();
URL.revokeObjectURL(a.href);
The spec doesn't specifically mention aborting existing streams when revoking a url, so in theory doing it like this would be just fine.
However, to be safe I would either revoke the url after a few seconds using setTimeout()
, or if the download is initiated from a specific screen, you can add logic to revoke it once the user navigates away from that screen.
Browsers also automatically revoke object urls once the last page of your domain is closed, so depending on your situation, not revoking urls at all might also be a viable solution.
setTimeout
? – Zoellick