Loading modern code for modern browsers while still supporting older browsers should be possible via module/nomodule:
<script type="module" src="/modern.js"></script>
<script nomodule src="/legacy.js"></script>
... however this results in over-fetching of scripts in Edge and Safari.