{"id":23094230,"url":"https://github.com/aswitalski/lazy-module-loader","last_synced_at":"2025-04-03T19:19:23.380Z","repository":{"id":19017002,"uuid":"85832020","full_name":"aswitalski/lazy-module-loader","owner":"aswitalski","description":"Async module loader with support for lazy loading and preloading","archived":false,"fork":false,"pushed_at":"2023-01-06T02:23:21.000Z","size":1181,"stargazers_count":0,"open_issues_count":8,"forks_count":2,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-04-14T19:43:08.778Z","etag":null,"topics":["async","lazy","lazy-loading","loader","module","preloading"],"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/aswitalski.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-03-22T13:38:49.000Z","updated_at":"2020-10-16T20:48:46.000Z","dependencies_parsed_at":"2023-01-11T20:30:31.500Z","dependency_job_id":null,"html_url":"https://github.com/aswitalski/lazy-module-loader","commit_stats":null,"previous_names":[],"tags_count":25,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aswitalski%2Flazy-module-loader","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aswitalski%2Flazy-module-loader/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aswitalski%2Flazy-module-loader/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aswitalski%2Flazy-module-loader/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/aswitalski","download_url":"https://codeload.github.com/aswitalski/lazy-module-loader/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247061882,"owners_count":20877176,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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","lazy","lazy-loading","loader","module","preloading"],"created_at":"2024-12-16T21:58:23.182Z","updated_at":"2025-04-03T19:19:23.359Z","avatar_url":"https://github.com/aswitalski.png","language":"JavaScript","readme":"# lazy-module-loader\n\nLazy Module Loader is a universal JavaScript module loader allowing to load modules with asynchronous resolution of their dependencies.\n\n[![Build Status](https://travis-ci.org/aswitalski/lazy-module-loader.svg?branch=master)](https://travis-ci.org/aswitalski/lazy-module-loader)\n[![npm version](https://img.shields.io/npm/v/lazy-module-loader.svg?style=flat)](https://www.npmjs.com/package/lazy-module-loader)\n\n## Intention\n\nLazy Module Loader had been widely used in Opera Desktop browser as a dedicated solution for modularity\nand bundling mechanism for Web UI code before the ES modules were fully supported.\n\n## Usage\n\nOnce the Lazy Module Loader script is loaded, it defines a global `loader` instance, which can be used as follows:\n\n```js\nconst module = await loader.require('my/module');\n```\n\nThe requested module is loaded with all its required dependencies resolved.\n\n## Path resolution\n\nBy default the resource path is caluclated with simple rules:\n\nNo extension - the JS file extension is appended:\n\n- `my/module` to `my/module.js`\n\nDirectory-like path - points to the main module in the directory:\n\n- `my/module/` to `my/module/main.js`\n\nCustom extension - returns the unchanged path:\n\n- `my/module/base.css` to `my/module/base.css`\n\n## Module format\n\nModules utilize the CommonJS format, they can define the `async init()` method which is used to inject references to dependencies.\n\n```js\nlet Sevice;\n\nconst Module = {\n\n  async init() {\n    Service = await loader.require('some/dependendency');\n  }\n\n  loadData() {\n    return Service.loadSomeData();\n  }\n};\n\nmodule.exports = Module;\n```\n\n## Lazy loading\n\nModules can also define optional dependencies (in a form of symbols) to other modules which are loaded at runtime, if needed.\nThis is particularly useful when no direct references are needed, for example:\n\n```js\nconst WelcomePage = loader.symbol('pages/welcome/');\nconst ContactPage = loader.symbol('pages/contact/');\n\nclass Router extends Component {\n\n  render() {\n    switch (this.props.page) {\n      case 'contact':\n        return ContactPage;\n      default:\n        return WelcomePage;\n    }\n  }\n}\n\nmodule.exports = Router;\n```\n\nThe dependencies don't have to be loaded until the router component decides to render the particular page.\n\n## Preloading\n\nIn order to achieve the maximum performance and responsiveness at runtime, modules can be preloaded at startup, not to lazy-load them upon user actions.\n\n```js\n\nconst module = await loader.preload('my/module');\n```\n\nSuch call will load recursively all the required and optional dependencies.\n\n## Bundling\n\nModules can also be bundled together with all their dependencies into a single file. What allows them to be loaded synchronously in a bunch.\n\n```js\nrequire('./bundler.js');\n\nbundler.generate('root/module', 'My Library', {\n  prefix: 'some/prefix/',\n});\n```\n\n## Plugins\n\nLoader can chain the interceptor plugins, to serve as a fallback to custom loaders.\n\n```js\nconst plugin = {\n  path(key) {\n    const path = super.path(key);\n    if (someCondition) {\n      return `http://www.example.com/module/${path}`;\n    }\n    return path;\n  },\n};\nloader.use(plugin);\n```\n\n## Registry\n\nAll the loaded modules are kept in a registry. It is global and can be accessed as follows:\n\n```js\nloader.registry\n```\n\n The registry is a map allowing to access the module information and easily analyze the dependency graph.\n Each module can be checked for all its dependencies and clients referencing it.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faswitalski%2Flazy-module-loader","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Faswitalski%2Flazy-module-loader","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faswitalski%2Flazy-module-loader/lists"}