Skip to content
This repository has been archived by the owner on Mar 18, 2024. It is now read-only.

On load fail handling #3

Open
aiboost opened this issue Aug 9, 2017 · 1 comment
Open

On load fail handling #3

aiboost opened this issue Aug 9, 2017 · 1 comment

Comments

@aiboost
Copy link

aiboost commented Aug 9, 2017

Hi,

Now there is no handling if one of specified images was NOT loaded (I tell about browser implementation).
This is bad for frontend applications not to have ability to handle such errors: if URL returns 404, the application just will discontinue working in the silence.

As I see the code:

const browserImage = Utils.createImage()
browserImage.addEventListener('load', () => {
   resolve(Image.fromImage(browserImage))
})
browserImage.crossOrigin = 'Anonymous'
browserImage.src = image

you use DOM API to load image.
So you can at least use this to handle failures:
https://stackoverflow.com/questions/9815762/detect-when-an-image-fails-to-load-in-javascript

But looks like this solution is not cross-browser (see link).
I suppose the best solution is to use File API.
I've tried to do this by myself, but I unable to convert read binary PNG (or any other format) data to BLOB to pass it to FileReader. Maybe you will get luck with this.

@aiboost
Copy link
Author

aiboost commented Aug 10, 2017

And one another pitfall for loading loading images data inside tag: if you use some API and load image at one URL many times, you will see that browser caches images and you can not be sure that image was really reloaded. Adding "?someUniqId" is not possible in some cases (you can break API URL format, this works guaranteed fine only if you request static files and only if there are no custom server limits).

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants