var chainPromises = function(scripts) {
var i = scripts.shift(),
s = document.createElement('script');
s.async = false;
s.src = i.src;
document.head.appendChild(s);
// ...
const chainScripts = src => src.reduce((acc, n) => {
return acc.then(() => new Promise((resolve, reject) => {
const s = document.createElement('script');
s.onload = resolve;
s.onerror = reject;
s.src = n;
document.head.appendChild(s);
}));
}, Promise.resolve());