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

dynamic-import

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

dynamic-import

Dynamically load scripts, components, css, and templates

  • 0.1.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
27
decreased by-85.71%
Maintainers
1
Weekly downloads
 
Created
Source

Build Status npm version

Dynamic Import

A library that allows you to dynamically load (and unload) scripts, CSS, and HTML templates and files in a browser.
Useful for preloading (in background), loading and unloading scripts inside the <head> of an html page, or cases when you may want to keep your css, js and templates in separate files and only want to import them into an HTML page at different times.

Installation

npm i dynamic-import

You can also use the dist files in the browser.

<script type="module" src="node_modules/dynamic-import/dist/import.min.js"></script>

Usage

Load CSS files

import { style } from 'node_modules/dynamic-import/dist/import.js';
const cssPaths = ['path/to/css/file.css', 'path/to/another/css/file.css'];
style.import(cssPaths).then(function () {
    // css files have been loaded!
});

Load JavaScript files

Load script files dynamically. When called, the supplied script will be loaded into the <head> of the DOM and run immediately.

import { script } from 'node_modules/dynamic-import/dist/import.js';
script.import('path/to/file.js').then(function () {
    // script has been loaded into the `<head>` of document!
});

Load HTML files

Load HTML file contents into an already-existing DOM element.

import { html } from 'node_modules/dynamic-import/dist/import.js';
html.import('path/to/html/file.html', document.body).then(function () {
    // html contents have been loaded into the body element
});

Keywords

FAQs

Package last updated on 03 Dec 2018

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