I created a slideshow that grabbed images from an external server. But doing work on my localhost, if the Internet went down, the slideshow broke. So I wanted to figure out how to use a local fallback image so I could keep developing even if the Internet failed.

Turns out it’s quite simple. (my solution inspired by this answer on stackoverflow)

The <img> tag has an onerror attribute that you can use to set a fallback image in.

Here is a cutdown version of my code…

Hope that helps someone!