Socket
Socket
Sign inDemoInstall

load-script2

Package Overview
Dependencies
0
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    load-script2

Dynamic script loading for modern browsers


Version published
Weekly downloads
15K
increased by7.55%
Maintainers
1
Install size
6.23 kB
Created
Weekly downloads
 

Readme

Source

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

This package works in the browser with browserify. If you do not use a bundler, you can use the standalone script directly in a <script> tag.

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 size of load-script2 is 509 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.

Keywords

FAQs

Last updated on 27 Oct 2020

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc