You just described the new "picture" element. It's an element with one or more "source" child elements which each have a media query and a uri, as well as an img child element to use as a fallback for non-supporting browsers.
Browser support isn't really there yet but it's coming and since it has a built-in fallback you can use it now without requiring JS workarounds.