2.0.0 • Published 4 years ago

load-script v2.0.0

Weekly downloads
846,976
License
MIT
Repository
github
Last release
4 years ago

load-script

Dynamic script loading.

Installation

via component

$ component install eldargab/load-script

via npm

$ npm install load-script

API

load-script appends a script node to the <head> element in the dom.

require('load-script') returns a function of the following interface: function(url[, opts][, cb]) {}

url

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

, opts

A map of options. Here are the currently supported options:

  • async - A boolean value used for script.async. By default this is true.
  • attrs - A map of attributes to set on the script node before appending it to the DOM. By default this is empty.
  • charset - A string value used for script.charset. By default this is utf8.
  • text - A string of text to append to the script node before it is appended to the DOM. By default this is empty.
  • type - A string used for script.type. By default this is text/javascript.

, cb

A callback function of the following interface: function(err, script) {} where err is an error if any occurred and script is the script node that was appended to the DOM.

Example Usage

var load = require('load-script')

load('foo.js', function (err, script) {
  if (err) {
    // print useful message
  }
  else {
    console.log(script.src);// Prints 'foo'.js'
    // use script
    // note that in IE8 and below loading error wouldn't be reported
  }
})

License

MIT

haravan-react-componentsreact-player-eurosport@riparide/react-playervue-canvas-video-player-betaaka-editorreact-sropbox-savercliniasearchreact-player-ott-supportreact-mathjax-updatedmingdao-web-mohodatahzero-boothzero-boot-pure@network-leads/contractscontracts-network-leads5-htp@nebulars/bury@nebular.js/bury@infinitebrahmanuniverse/nolb-loa@zawi/react-mathjax@linkiwi/react-mathjaxmingdao-web-mo@everything-registry/sub-chunk-2091snbc-paas-bootcpaas-bootwix-react-playervvv-searchform-widgetwaiqin365-modulewd-react-intl-universalvue-naver-mapws-canvasws-china-area-datasvelte-playertianji-client-sdkvpg-react-mathjaxvue-gpickervue-core-epic-playervue-coin-hivevue-core-video-playervue-core-video-playersviskan-deku-recaptchavue-dropbox-chooservue-ecommercevue-email-buildervue-canvas-video-player@rox123/import_test@prestashopcorp/chargebee-vue@prisma-cms/frontitem-bankitem-bank-2item-bank-customitem-bank-testireactplayerireact-playerkazuldur-react-playerkhuya-playerlazy-routerlatex2js-mathjaxidx-playergtaggergoogle-picker-componentload-script-globalload-script-oncelrm-video-playermaestro-react-playermap-distancemap-divm-zhinanmao-utilsm2m-chartjs-plugin-crosshairload-es6-promisereactjax@wingsplatform/pay@wendina/engine@webutils/uploader@webiny/ui@wizedemy/react-player@wix/ricos@webiny/app-graphql-playground@truto/truto-link-sdk@topol.io/editor@vibbio/react-player@vibbio/react-player-2@vibbio/slideshow-player@vibbio/time-marker@valosan/react-google-picker@voltra/vue-player@yelo/geo-position@zaptime/vue3alloyeditor-react-componentamap-divairtapairmap-map-sdkairframe-redely-ckeditor4-vue@cloudgeek/playcore-hls@cloudgeek/vue3-video-player@gorangajic/react-soundcloud-widget@granatum/react-player5htp-core@0x1461a0/sd-plugin-entry@haravan/react-components@harambe-tv/react-player
2.0.0

4 years ago

1.0.0

11 years ago

0.0.5

12 years ago

0.0.4

12 years ago

0.0.3

12 years ago

0.0.2

12 years ago