kubetail-org / loadjs

A tiny async loader / dependency manager for modern browsers (899 bytes)
MIT License
2.57k stars 149 forks source link

Image loading and error handling #91

Open hkvstore opened 5 years ago

hkvstore commented 5 years ago

I'd like to report 2 issues I found when playing with this excellent script:

  1. The script will insert image tag into \. Since the onload/onerror events will be fired after setting src, it might be better not to append the image to \.

  2. I accidentally passed a blank array as paths to loadjs(), it could pass the loadFiles() without firing callbackFn(), the subsequent loading process was therefore skipped. It would be nice if some error handling about that can be added.

Thank you for creating such a good script.

amorey commented 5 years ago

Happy to hear you like LoadJS! In terms of your issues, what's the disadvantage to inserting image tags into <head>? I tested it across browsers and didn't see any issues.

Let me think about the error handling for blank arrays some more...

wklau2006 commented 5 years ago

Thank you for your reply. I didn't see any issues with Chrome too, but as mentioned, the onload/onerror events will be fired after setting src, preloading is done, no need to do more. I understand it needs to add extra code (e.tagName != "IMG") to distinguish images but this will keep the DOM clean. Only a tiny suggestion to make loadjs even better. Thanks.