Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@paciolan/remote-module-loader

Package Overview
Dependencies
Maintainers
1
Versions
24
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@paciolan/remote-module-loader

  • 2.0.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
5.9K
decreased by-24.46%
Maintainers
1
Weekly downloads
 
Created
Source

Remote Module Loader pipeline status coverage report

Loads a module from a remote url.

Use Cases

Lazy Load Modules to keep initial load times down and load modules just in time.

Update Remote Modules independent of the web application. Update a module without redeploying the web application.

Install

npm install @paciolan/remote-module-loader

createLoadRemoteModule

Simple Example

If your module has no external dependencies, this is the easiest method to fetch the remote module.

/**
 * src/lib/loadRemoteModule.js
 */

import { createLoadRemoteModule } from "@paciolan/remote-module-loader";

export default createLoadRemoteModule();

Require Example

You can pass dependencies to the module.

/**
 * src/lib/loadRemoteModule.js
 */

import { createLoadRemoteModule } from "@paciolan/remote-module-loader";

// dependencies for the loaded module.
const dependencies = {
  react: require("react")
};

// requires method exposes dependencies to the loaded module.
const requires = name => dependencies[name];

export default createLoadRemoteModule({ requires });

Using your own fetcher

By default loadRemoteModule will use the XMLHttpRequest object avaiable in the browser. This can be overridden if you want to use an alternate method.

/**
 * src/lib/loadRemoteModule.js
 */

import { createLoadRemoteModule } from "@paciolan/remote-module-loader";
import axios from "axios";

const fetcher = url => axios.get(url).then(request => request.data);

export default createLoadRemoteModule({ fetcher });

Usage

Modules are loaded asynchronously, so use similar techniques to any other async function.

/**
 * src/index.js
 */

import loadRemoteModule from "./lib/loadRemoteModule";

const myModule = loadRemoteModule("http://fake.url/modules/my-module.js");

myModule.then(m => {
  const value = m.default();
  console.log({ value });
});

Contributors

Joel Thoms (jthoms@paciolan.com)

Icon made by Freepik from www.flaticon.com

FAQs

Package last updated on 01 Apr 2019

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc