Giter VIP home page Giter VIP logo

load-script2's Introduction

load-script2 travis npm downloads javascript style guide

Dynamic script loading for modern browsers

Works in the browser with browserify!

install

npm install load-script2

usage

const loadScript = require('load-script2')

const script = await loadScript('foo.js')
console.log(script.src);// Prints 'foo'.js'

differences to load-script

load-script2 does not support legacy browsers like IE8 because these browsers do not have standards-based DOM APIs. load-script2 also removes many esoteric options, which aren't needed most of the time and adds promises support.

The sise of load-script2 is 492 bytes, compared to 655 bytes for load-script (minified and gzipped).

API

promise = loadScript(src, [attrs], [parentNode])

Append a <script> node with the given src URL to the <head> element in the DOM.

src

Any url that you would like to load. May be absolute or relative.

attrs (optional)

An object that contains HTML attributes to set on the <script> tag. For example, the value { id: 'hi' } would set the attribute id="hi" on the <script> tag before it is injected.

parentNode (optional)

The HTML node to which the <script> tag will be appended. If not specified, defaults to the <head> tag.

promise

Returns a promise which resolves to the script node that was appended to the DOM, or rejects with err if any occurred.

license

MIT. Copyright (c) Feross Aboukhadijeh.

load-script2's People

Contributors

feross avatar greenkeeper[bot] avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.