Last active
October 26, 2023 09:36
-
-
Save hungtcs/5734cf5b8ebe55a3b758c21c93df75e0 to your computer and use it in GitHub Desktop.
Show fallback image when image loading fails
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<object data="path/to/image-00.png" type="image/png"> | |
<img src="path/to/fallback.png" /> | |
</object> | |
<!-- why not this --> | |
<img src="path/to/image-00.png" onerror="this.src = 'path/to/fallback.png'" /> | |
<!-- 1. object is a pure html solution and does not require js. --> | |
<!-- 2. if the backup image fails to load, there is a risk of an infinite loop --> | |
<!-- 3. however, the object tag has a larger overhead --> | |
<!-- 4. maybe I should create a web component that supports regression to replace the above --> | |
<!-- and --> | |
<img src="path/to/image-00.png" onerror="this.onerror = null; this.src = 'path/to/fallback.png'" /> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment