In this example, where going to setup polyfills for Promise and window.fetch. We'll start by adding a polyfill from npm.
yarn add whatwg-fetch promise-polyfill
For most cases, the polyfills need to be loaded above the application.js file because it might need to use them during application.js execution. We'll create a script that will be executed as the page is loaded and if a polyfill does not exist then it'll add the appropriate polyfill script file. The polyfill will be downloaded, parsed, and executed before the application.js.