{"id":27615380,"url":"https://github.com/amorey/loadjs","last_synced_at":"2026-03-09T18:38:42.081Z","repository":{"id":34808301,"uuid":"38794215","full_name":"amorey/loadjs","owner":"amorey","description":"A tiny async loader / dependency manager for modern browsers (961 bytes)","archived":false,"fork":false,"pushed_at":"2024-09-26T06:27:15.000Z","size":748,"stargazers_count":2585,"open_issues_count":36,"forks_count":148,"subscribers_count":72,"default_branch":"main","last_synced_at":"2025-12-13T08:54:04.628Z","etag":null,"topics":["async","css-files","javascript","loadjs","modern-browsers","parallel"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/amorey.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":"AUTHORS.txt","dei":null,"publiccode":null,"codemeta":null},"funding":{"github":"amorey"}},"created_at":"2015-07-09T03:17:32.000Z","updated_at":"2025-12-09T13:14:49.000Z","dependencies_parsed_at":"2024-09-30T14:20:59.885Z","dependency_job_id":"30e568b7-02b3-4351-b615-b1534eadc1a1","html_url":"https://github.com/amorey/loadjs","commit_stats":null,"previous_names":["kubetail-org/loadjs","muicss/loadjs","amorey/loadjs"],"tags_count":29,"template":false,"template_full_name":null,"purl":"pkg:github/amorey/loadjs","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/amorey%2Floadjs","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/amorey%2Floadjs/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/amorey%2Floadjs/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/amorey%2Floadjs/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/amorey","download_url":"https://codeload.github.com/amorey/loadjs/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/amorey%2Floadjs/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":30307548,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-09T17:35:44.120Z","status":"ssl_error","status_checked_at":"2026-03-09T17:35:43.707Z","response_time":61,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["async","css-files","javascript","loadjs","modern-browsers","parallel"],"created_at":"2025-04-23T03:02:03.547Z","updated_at":"2026-03-09T18:38:42.067Z","avatar_url":"https://github.com/amorey.png","language":"JavaScript","readme":"# LoadJS\n\n\u003cimg src=\"https://www.muicss.com/static/images/loadjs.svg\" width=\"250px\"\u003e\n\nLoadJS is a tiny async loader for modern browsers (961 bytes).\n\n[![CDNJS](https://img.shields.io/cdnjs/v/loadjs.svg)](https://cdnjs.com/libraries/loadjs)\n\n## Introduction\n\nLoadJS is a tiny async loading library for modern browsers (IE9+). It has a simple yet powerful dependency management system that lets you fetch JavaScript, CSS and image files in parallel and execute code after the dependencies have been met. The recommended way to use LoadJS is to include the minified source code of [loadjs.js](https://raw.githubusercontent.com/kubetail-org/loadjs/main/dist/loadjs.min.js) in your \u0026lt;html\u0026gt; (possibly in the \u0026lt;head\u0026gt; tag) and then use the `loadjs` global to manage JavaScript dependencies after pageload.\n\nLoadJS is based on the excellent [$script](https://github.com/ded/script.js) library by [Dustin Diaz](https://github.com/ded). We kept the behavior of the library the same but we re-wrote the code from scratch to add support for success/error callbacks and to optimize the library for modern browsers. LoadJS is 961 bytes (minified + gzipped).\n\nHere's an example of what you can do with LoadJS:\n\n```html\n\u003cscript src=\"//unpkg.com/loadjs@latest/dist/loadjs.min.js\"\u003e\u003c/script\u003e\n\u003cscript\u003e\n  // define a dependency bundle and execute code when it loads\n  loadjs(['/path/to/foo.js', '/path/to/bar.js'], 'foobar');\n\n  loadjs.ready('foobar', function() {\n    /* foo.js \u0026 bar.js loaded */\n  });\n\u003c/script\u003e\n```\n\nYou can also use more advanced syntax for more options:\n```html\n\u003cscript src=\"//unpkg.com/loadjs@latest/dist/loadjs.min.js\"\u003e\u003c/script\u003e\n\u003cscript\u003e\n  // define a dependency bundle with advanced options\n  loadjs(['/path/to/foo.js', '/path/to/bar.js'], 'foobar', {\n    before: function(path, scriptEl) { /* execute code before fetch */ },\n    async: true,  // load files synchronously or asynchronously (default: true)\n    numRetries: 3,  // see caveats about using numRetries with async:false (default: 0)\n    returnPromise: false  // return Promise object (default: false)\n  });\n\n  loadjs.ready('foobar', {\n    success: function() { /* foo.js \u0026 bar.js loaded */ },\n    error: function(depsNotFound) { /* foobar bundle load failed */ },\n  });\n\u003c/script\u003e  \n```\n\nThe latest version of LoadJS can be found in the `dist/` directory in this repository:\n * [https://cdn.rawgit.com/kubetail-org/loadjs/4.3.0/dist/loadjs.js](https://cdn.rawgit.com/kubetail-org/loadjs/4.3.0/dist/loadjs.js) (for development)\n * [https://cdn.rawgit.com/kubetail-org/loadjs/4.3.0/dist/loadjs.min.js](https://cdn.rawgit.com/kubetail-org/loadjs/4.3.0/dist/loadjs.min.js) (for production)\n\nIt's also available from these public CDNs:\n\n  * UNPKG\n    * [https://unpkg.com/loadjs@4.3.0/dist/loadjs.js](https://unpkg.com/loadjs@4.3.0/dist/loadjs.js) (for development)\n    * [https://unpkg.com/loadjs@4.3.0/dist/loadjs.min.js](https://unpkg.com/loadjs@4.3.0/dist/loadjs.min.js) (for production)\n  * CDNJS\n    * [https://cdnjs.cloudflare.com/ajax/libs/loadjs/4.3.0/loadjs.js](https://cdnjs.cloudflare.com/ajax/libs/loadjs/4.3.0/loadjs.js) (for development)\n    * [https://cdnjs.cloudflare.com/ajax/libs/loadjs/4.3.0/loadjs.min.js](https://cdnjs.cloudflare.com/ajax/libs/loadjs/4.3.0/loadjs.min.js) (for production)\n\nYou can also use it as a CJS or AMD module:\n\n```bash\n$ npm install --save loadjs\n```\n\n```javascript\nvar loadjs = require('loadjs');\n\nloadjs(['/path/to/foo.js', '/path/to/bar.js'], 'foobar');\n\nloadjs.ready('foobar', function() {\n  /* foo.js \u0026 bar.js loaded */\n});\n```\n\n## Browser Support\n\n * IE9+ (`async: false` support only works in IE10+)\n * Opera 12+\n * Safari 5+\n * Chrome\n * Firefox\n * iOS 6+\n * Android 4.4+\n\nLoadJS also detects script load failures from AdBlock Plus and Ghostery in:\n\n * Safari\n * Chrome\n\nNote: LoadJS treats empty CSS files as load failures in IE9-11 and uses `rel=\"preload\"` to load CSS files in Edge (to get around lack of support for onerror events on `\u003clink rel=\"stylesheet\"\u003e` tags)\n\n## Documentation\n\n1. Load a single file\n\n    ```javascript\n    loadjs('/path/to/foo.js', function() {\n      /* foo.js loaded */\n    });\n    ```\n\n1. Fetch files in parallel and load them asynchronously\n\n    ```javascript\n    loadjs(['/path/to/foo.js', '/path/to/bar.js'], function() {\n      /* foo.js and bar.js loaded */\n    });\n    ```\n\n1. Fetch JavaScript, CSS and image files\n\n    ```javascript\n    loadjs(['/path/to/foo.css', '/path/to/bar.png', 'path/to/thunk.js'], function() {\n      /* foo.css, bar.png and thunk.js loaded */\n    });\n    ```\n\n1. Force treat file as CSS stylesheet\n\n    ```javascript\n    loadjs(['css!/path/to/cssfile.custom'], function() {\n      /* cssfile.custom loaded as stylesheet */\n    });\n    ```\n\n1. Force treat file as image\n\n    ```javascript\n    loadjs(['img!/path/to/image.custom'], function() {\n      /* image.custom loaded */\n    });\n    ```\n\n1. Load JavaScript files as modules with non-module fallbacks (in browsers without module support)\n\n    ```javascript\n    loadjs(['module!/path/to/foo.js', 'nomodule!/path/to/bar.js'], function() {\n        /* foo.js loaded with type=\"module\" in browsers with module support, skipped silently in browsers without */\n        /* bar.js loaded with type=\"text/javascript\" in browsers without module support, skipped silently in browsers with */\n    });\n    ```\n\n1. Add a bundle id\n\n    ```javascript\n    loadjs(['/path/to/foo.js', '/path/to/bar.js'], 'foobar', function() {\n      /* foo.js \u0026 bar.js loaded */\n    });\n    ```\n\n1. Use .ready() to define bundles and callbacks separately\n\n    ```javascript\n    loadjs(['/path/to/foo.js', '/path/to/bar.js'], 'foobar');\n\n    loadjs.ready('foobar', function() {\n      /* foo.js \u0026 bar.js loaded */\n    });\n    ```\n\n1. Use multiple bundles in .ready() dependency lists\n\n    ```javascript\n    loadjs('/path/to/foo.js', 'foo');\n    loadjs(['/path/to/bar1.js', '/path/to/bar2.js'], 'bar');\n\n    loadjs.ready(['foo', 'bar'], function() {\n      /* foo.js \u0026 bar1.js \u0026 bar2.js loaded */\n    });\n    ```\n\n1. Chain .ready() together\n\n    ```javascript\n    loadjs('/path/to/foo.js', 'foo');\n    loadjs('/path/to/bar.js', 'bar');\n\n    loadjs\n      .ready('foo', function() {\n        /* foo.js loaded */\n      })\n      .ready('bar', function() {\n        /* bar.js loaded */\n      });\n    ```\n\n1. Use Promises to register callbacks\n\n   ```javascript\n   loadjs(['/path/to/foo.js', '/path/to/bar.js'], {returnPromise: true})\n     .then(function() { /* foo.js \u0026 bar.js loaded */ })\n     .catch(function(pathsNotFound) { /* at least one didn't load */ });\n   ```\n\n1. Check if bundle has already been defined\n\n    ```javascript\n    if (!loadjs.isDefined('foobar')) {\n      loadjs(['/path/to/foo.js', '/path/to/bar.js'], 'foobar', function() {\n        /* foo.js \u0026 bar.js loaded */\n      });\n    }\n    ```\n\n1. Fetch files in parallel and load them in series\n\n    ```javascript\n    loadjs(['/path/to/foo.js', '/path/to/bar.js'], {\n      success: function() { /* foo.js and bar.js loaded in series */ },\n      async: false\n    });\n    ```\n\n1. Add an error callback\n\n    ```javascript\n    loadjs(['/path/to/foo.js', '/path/to/bar.js'], 'foobar', {\n      success: function() { /* foo.js \u0026 bar.js loaded */ },\n      error: function(pathsNotFound) { /* at least one path didn't load */ }\n    });\n    ```\n\n1. Retry files before calling the error callback\n\n    ```javascript\n    loadjs(['/path/to/foo.js', '/path/to/bar.js'], 'foobar', {\n      success: function() { /* foo.js \u0026 bar.js loaded */ },\n      error: function(pathsNotFound) { /* at least one path didn't load */ },\n      numRetries: 3\n    });\n    \n    // NOTE: Using `numRetries` with `async: false` can cause files to load out-of-sync on retries\n    ```\n\n1. Execute a callback before script tags are embedded\n\n    ```javascript\n    loadjs(['/path/to/foo.js', '/path/to/bar.js'], {\n      success: function() {},\n      error: function(pathsNotFound) {},\n      before: function(path, scriptEl) {\n        /* called for each script node before being embedded */\n        if (path === '/path/to/foo.js') scriptEl.crossOrigin = true;\n      }\n    });\n    ```\n\n1. Bypass LoadJS default DOM insertion mechanism (DOM `\u003chead\u003e`)\n\n    ```javascript\n    loadjs(['/path/to/foo.js'], {\n      success: function() {},\n      error: function(pathsNotFound) {},\n      before: function(path, scriptEl) {\n        document.body.appendChild(scriptEl);\n      \n        /* return `false` to bypass default DOM insertion mechanism */\n        return false;\n      }\n    });\n    ```\n\n1. Use bundle ids in error callback\n\n    ```javascript\n    loadjs('/path/to/foo.js', 'foo');\n    loadjs('/path/to/bar.js', 'bar');\n    loadjs(['/path/to/thunkor.js', '/path/to/thunky.js'], 'thunk');\n\n    // wait for multiple depdendencies\n    loadjs.ready(['foo', 'bar', 'thunk'], {\n      success: function() {\n        // foo.js \u0026 bar.js \u0026 thunkor.js \u0026 thunky.js loaded\n      },\n      error: function(depsNotFound) {\n        if (depsNotFound.indexOf('foo') \u003e -1) {};  // foo failed\n        if (depsNotFound.indexOf('bar') \u003e -1) {};  // bar failed\n        if (depsNotFound.indexOf('thunk') \u003e -1) {};  // thunk failed\n      }\n    });\n    ```\n  \n1. Use .done() for more control\n\n    ```javascript\n    loadjs.ready(['dependency1', 'dependency2'], function() {\n      /* run code after dependencies have been met */\n    });\n\n    function fn1() {\n      loadjs.done('dependency1');\n    }\n  \n    function fn2() {\n      loadjs.done('dependency2');\n    }\n    ```\n\n1. Reset dependency trackers\n\n    ```javascript\n    loadjs.reset();\n    ```\n\n1. Implement a require-like dependency manager\n\n    ```javascript\n    var bundles = {\n      'bundleA': ['/file1.js', '/file2.js'],\n      'bundleB': ['/file3.js', '/file4.js']\n    };\n\n    function require(bundleIds, callbackFn) {\n      bundleIds.forEach(function(bundleId) {\n        if (!loadjs.isDefined(bundleId)) loadjs(bundles[bundleId], bundleId);\n      });\n      loadjs.ready(bundleIds, callbackFn);\n    }\n\n    require(['bundleA'], function() { /* bundleA loaded */ });\n    require(['bundleB'], function() { /* bundleB loaded */ });\n    require(['bundleA', 'bundleB'], function() { /* bundleA and bundleB loaded */ });\n    ```\n\n## Directory structure\n\n\u003cpre\u003e\nloadjs/\n├── dist\n│   ├── loadjs.js\n│   ├── loadjs.min.js\n│   └── loadjs.umd.js\n├── examples\n├── gulpfile.js\n├── LICENSE.txt\n├── package.json\n├── README.md\n├── src\n│   └── loadjs.js\n├── test\n└── umd-templates\n\u003c/pre\u003e\n\n## Development Quickstart\n\n1. Install dependencies\n\n    * [nodejs](http://nodejs.org/)\n    * [npm](https://www.npmjs.org/)\n    * http-server (via npm)\n\n1. Clone repository\n\n    ```bash\n    $ git clone git@github.com:kubetail-org/loadjs.git\n    $ cd loadjs\n    ```\n\n1. Install node dependencies using npm\n\n    ```bash\n    $ npm install\n    ```\n\n1. Build examples\n\n    ```bash\n    $ npm run build-examples\n    ```\n\n    To view the examples you can use any static file server. To use the `nodejs` http-server module:\n\n    ```bash\n    $ npm install http-server\n    $ npm run http-server -- -p 3000\n    ```\n\n    Then visit [http://localhost:3000/examples](http://localhost:3000/examples)\n\n1. Build distribution files\n\n    ```bash\n    $ npm run build-dist\n    ```\n\n    The files will be located in the `dist` directory.\n\n1. Run tests\n\n     To run the browser tests first build the `loadjs` library:\n\n     ```bash\n     $ npm run build-tests\n     ```\n\n     Then visit [http://localhost:3000/test](http://localhost:3000/test)\n\n1. Build all files\n\n     ```bash\n     $ npm run build-all\n     ```\n\n","funding_links":["https://github.com/sponsors/amorey"],"categories":["javascript","JavaScript"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Famorey%2Floadjs","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Famorey%2Floadjs","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Famorey%2Floadjs/lists"}