page-preloader

1.2.44 • Public • Published

PAGE PRELOADER

npm version Build Status codecov JavaScript Style Guide: Good Parts

A simple page preloader using a dedicated web worker.

☁️ Installation

npm install page-preloader

📋 Example

import { PagePreloader } from 'page-preloader';
// let { PagePreloader } = require('page-preloader')
 
// use default options
PagePreloader.init()
 
PagePreloader.query("https://www.example.com", "/api/products?page=1&category=baz")
 
window.__preloadedData
// Preloaded data are available inside this global variable
// You should negotiate this object before requesting raw data for a new page

📝 Documentation

PagePreloader.init(options)

Initializes internal flow of code.

Usage:

PagePreloader.init({
    debug: false, // default
    // Turns debug mode on or off.
    
    preloadKey: 'uri', // default
    // Saves preloaded data for a certain page under this key.
    // - 'uri' - saves data using URI string. Example: { '/api/products?page=1': ..data.. }
    // - 'page' - saves data using page number. Example: { 1: ..data.. }
    
    preloadDelay: 2000, // default
    // Determines delay in [ms] after which to start preloading.
    
    cacheDuration: 60000, // default
    // Determines cache duration in [ms] for preloaded data
    // Once the duration period expires, data are requested again.
    
    maxInactivityTicks: 20, // default
    // Determines ticks for inactivity period.
    // One tick expires whenever preloaded page history remains unchanged following cache expiration.
})

Params

  • object options: Configuration object.

Return

  • void

PagePreloader.query(origin, endPoint)

Queries requested resource.

Usage:

PagePreloader.query(origin, endPoint)

Params

  • string origin: Requested resource base URL (eg. https://www.example.com).
  • string endPoint: Requested resource end-point (eg. /api/products?page=1&category=baz).

Return

  • void

window.__preloadedData

Container for preloaded data.

Usage:

window.__preloadedData
// Preloaded data are available inside this global variable
// You should negotiate this object before requesting raw data for a new page

LICENSE

MIT

Package Sidebar

Install

npm i page-preloader

Weekly Downloads

29

Version

1.2.44

License

MIT

Unpacked Size

66.6 kB

Total Files

27

Last publish

Collaborators

  • mall