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

asyncei

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

asyncei

Pure JS, lighweight, asynchronous content loader

  • 1.0.2
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
0
decreased by-100%
Maintainers
1
Weekly downloads
 
Created
Source

Asyncei

Pure JS, lighweight, asynchronous content loader

Install

npm install --save-dev asyncei

Quick start

  1. First, initialize Asyncei:
import Asyncei from 'asyncei';
new Asyncei('/path/to/handler/');
  1. Then, in your HTML do:
<div data-fetch="subpath/to/block"></div>
  1. Watch your block loading asynchronous! 🎉

How it works?

  1. Asyncei queries page in the lookup for specified attribute;
  2. Fetches all found urls asynchronously;
  3. Fetches images in each loaded content block;
  4. Dispatches blockContentLoaded event, on the load of the a block;
  5. After all blocks are loaded dispatches allBlocksLoaded event;

API

Customization

When initializing Asyncei three parameters may be set:

  1. handlerURL – (required) URL for content loading handler.
  2. renderFunction – Function to handle content rendering.

Should take two params: element – DOM Element, and text – string of content. Default one is:

(element, text) => {element.innerHTML = text}
  1. queryAttribute – Attribute to query in search of loadable blocks. Default is data-fetch.

Events

Each block load triggers custom event blockContentLoaded. Example:

let example = document.getElementById('example-component');
example ? example.addEventListener('blockContentLoaded', () => onExampleLoad()) : null;

If all blocks queried on page are loaded, custom event allBlocksLoaded is triggered. Example:

document.addEventListener('allBlocksLoaded', () => onAllLoaded());

Demo

Find our demo here: preload-demo repository

Keywords

FAQs

Package last updated on 30 Aug 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