FileSaver.js
FileSaver.js copied to clipboard
Why is there a 40-second delay in calling the `URL.revokeObjectURL` method?
I asked same question on Stack Overflow, see here.
The source code FileSaver.js#L106
a.href = URL.createObjectURL(blob)
setTimeout(function () { URL.revokeObjectURL(a.href) }, 4E4) // 40s
setTimeout(function () { click(a) }, 0)
Why is there a 40-second delay in calling the URL.revokeObjectURL method? Why don't call it immediately after calling URL.createObjectURL(blob)?
https://developer.mozilla.org/en-US/docs/Web/API/URL/revokeObjectURL_static
The revokeObjectURL() static method of the URL interface releases an existing object URL which was previously created by calling URL.createObjectURL().
Call this method when you've finished using an object URL to let the browser know not to keep the reference to the file any longer.
So the 40-second delay is just to relase the resource, prevent any memory leak.
https://developer.mozilla.org/en-US/docs/Web/API/URL/revokeObjectURL_static
The revokeObjectURL() static method of the URL interface releases an existing object URL which was previously created by calling URL.createObjectURL().
Call this method when you've finished using an object URL to let the browser know not to keep the reference to the file any longer.
So the 40-second delay is just to relase the resource, prevent any memory leak.
Why 40 seconds rather than 30 seconds or 60 seconds?
Maybe 40 seconds or 30 seconds or 60 seconds are all okay, seems to don't matter. I guess it's just used to wait and ensure the file is downloaded completely.
It's completely arbitrary. This is an unfortunate side effect of the web platform not having 'download completed' events