🔮 mastic-fetcher 🌟
Automatically tests your browser for the features you want, and then fetches the polyfills
How to use it
First, install mastic-fetcher as one of your dependencies :
npm i mastic-fetcher --save
You'll need to provide three things to mastic-fetcher :
- a list of polyfills to test
- an url to fetch the polyfills if needed
- a list of scripts to load and execute when the browser is polyfilled and ready to rock
;; ;
fill()
options
polyfills
Array
of Polyfill
objects
The list of polyfills the fill script will test and fetch if needed. You can import and use the ones from mastic-polyfills
, but you can also make it work with your hand-made polyfills :
;; const isFeatureSupported = typeof feature !== 'undefined';const myBundleName = 'feature-polyfill';const myPolyfill = isFeatureSupported customBundleName; ;
For more information on polyfills objects, see the mastic-polyfills readme.
url
String
The url of the server serving your polyfills bundles. See the mastic-node-server readme for more information.
scripts
Array
of String
To be able to polyfill your browser before your app code runs, mastic-fetcher
must control the script loading and executing order. It means you have to remove the scripts tags from your pages, and provide the urls to mastic-fetcher
. It can be done with a global variable or anything you want.
- <script src="/assets/app.js"></script>+ <script>window.scripts=['/assets/app.js']></script>
;
You can improve the loading speed of your scripts in the browsers supporting resources preload (mainly Chrome for the moment) by adding some lines in the header of your page :
This will preload the scripts you specify without executing them, so when mastic-fetcher
will want to execute them they will already be in loaded in cache.