New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

async-components-loader

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

async-components-loader

Dynamically load JavaScript modules from the DOM using data-component attributes.

latest
Source
npmnpm
Version
1.0.0
Version published
Maintainers
1
Created
Source

async-components-loader

npm version npm downloads license

📦 Dynamically load JavaScript modules based on data-component attributes in the DOM. Each module must export a run() function that will be executed automatically.

🚀 Installation

npm install async-components-loader

📖 Usage

1. Define your components in the DOM

<div data-component="Hello"></div>
<div data-component="World"></div>

2. Create your dynamic modules

Each component should export a run function:

// /components/Hello/index.ts
export function run() {
  console.log("Hello component loaded!");
}
// /components/World/index.ts
export function run() {
  console.log("World component loaded!");
}

3. Initialize the loader in your project

import { init } from "async-components-loader";

init();
// 🔥 This will scan all elements with [data-component],
// dynamically import their modules and execute `run()`.

⚙️ Options

You can specify the base path where your components are located:

init("../custom-path/components");

By default, it looks for modules in ../components.

✅ Full Example

import { init } from "async-components-loader";

// Run all components declared in the DOM
document.addEventListener("DOMContentLoaded", () => {
  init();
});

🛠️ Local Development

Clone the repo and build:

git clone https://github.com/Lauc1an/async-components-loader.git
cd async-components-loader
npm install
npm run build

📜 License

MIT License

Copyright © 2025 Alexander Pomareda

Keywords

async

FAQs

Package last updated on 06 Sep 2025

Did you know?

Socket

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