Skip to content

FND/tiny-script-loader

Repository files navigation

tiny, dependency-free JavaScript loader — intended primarily for loading polyfills or common libraries up front

loadScripts(["foo.js", "bar.js", "baz.js"], function() {
    // all aforementioned scripts have been loaded
});

(scripts are loaded and executed sequentially)

you can also pass an object in order to assign arbitrary attributes to the generated script tag, e.g. for Subresource Integrity:

loadScripts([{
    src: "https://cdn.example.org/lib.js",
    integrity: "sha256-Ijl…1bE=",
    crossorigin: "anonymous"
}]);

prompted by Loading Polyfills Only When Needed, which explains why document.write should be avoided

see samples directory for usage examples

About

minimal JavaScript loader, intended for loading polyfills up front

Resources

Stars

Watchers

Forks

Packages

No packages published