https://cdn.polyfill.io/v3/url-builder/ is pretty great for this, it'll detect the browser user agent and send down the right polyfill. Ie on modern browsers it'll send down an empty response.
If I'd use it for all polyfills (which we should maybe consider!), we'd likely self-host the service.