page-preloader
v1.2.44
Published
Preload pages via web worker
Downloads
14
Readme
A simple page preloader using a dedicated web worker.
:cloud: Installation
npm install page-preloader
:clipboard: 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
:memo: 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