• Stars
    star
    146
  • Rank 252,769 (Top 5 %)
  • Language
    JavaScript
  • Created almost 12 years ago
  • Updated about 3 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Dynamic script loading

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

More Repositories

1

easy-table

Nice text table for Node.js
JavaScript
302
star
2

node-fake-fs

Fake node.js file system for testing
JavaScript
32
star
3

component-as-module

Require components from node programs
JavaScript
19
star
4

easy-app

Structure for large and small applications
JavaScript
15
star
5

agent-next

Simple, flexible, fun to use HTTP agent with nice API and clean implementation
JavaScript
12
star
6

LT-Opener

LightTable plugin that helps to open terminals, dirs and files
JavaScript
11
star
7

translit

Text transliteration util
JavaScript
11
star
8

translit-russian

Russian transliteration map
JavaScript
10
star
9

parse-fn-args

Parse function arguments
JavaScript
9
star
10

make-flow

Make style control flow
JavaScript
8
star
11

connect-views

Serve your jades, markdowns, lesses, etc like static files
JavaScript
5
star
12

google-maps

Load google maps from JavaScript
JavaScript
5
star
13

the-box

Deprecated (see easy-app instead)
JavaScript
4
star
14

reuse.js

Funky way to extend your objects
JavaScript
3
star
15

arabic-translit

Non-traditional, non-keyboard-macro, fluent transliteration for arabic language.
JavaScript
3
star
16

heap

Javascript implementation of Binary heap data structure
JavaScript
3
star
17

component-npm-post-install

Post install script for npm(1) which makes components consumable from node
JavaScript
3
star
18

LT-AltTab

LightTable plugin that provides windows Alt+Tab like experience for navigation between tabs.
JavaScript
3
star
19

hooks-emitter

Event emitter, but for hooks
JavaScript
2
star
20

calc.js

Toy CLI calculator. Implementation of Pratt's top down operator precedence parsing technique.
JavaScript
2
star
21

linked-list.js

Benchmarks for linked list structure
JavaScript
2
star
22

go-async

Generator based async/await blocks with support for abortion, form of TCO and fast synchronous execution.
JavaScript
2
star
23

print.js

Mini template (format) function for html, urls, etc
JavaScript
2
star
24

express-site

Quick server for static websites
JavaScript
1
star
25

frp

Playground for FRP
JavaScript
1
star
26

easy-streaming

The way to do streaming in node.js preferred by me
JavaScript
1
star
27

dx-custom-types

Custom types generation example for HydraDX chain
TypeScript
1
star
28

sublime-settings

My settings for the Sublime Text editor
Python
1
star
29

codemirror

CodeMirror in browser editor as a component
JavaScript
1
star
30

LT-NoQuestions

Never ask "Do you want to save..?" questions :)
JavaScript
1
star
31

sandbox

Just a sandbox for new projects
1
star
32

hydradx-example

TypeScript
1
star
33

exposer.js

Compiles and bundles things for browser
JavaScript
1
star
34

async-reduce

Function for async reductions on arrays with concurrency support as well
JavaScript
1
star