https://github.com/somewind/idle-preload
preload something when the page is idle
https://github.com/somewind/idle-preload
frontend idle preload web
Last synced: 4 months ago
JSON representation
preload something when the page is idle
- Host: GitHub
- URL: https://github.com/somewind/idle-preload
- Owner: somewind
- License: mit
- Created: 2019-07-24T07:19:51.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2023-01-04T05:20:54.000Z (over 3 years ago)
- Last Synced: 2025-10-22T01:59:48.103Z (8 months ago)
- Topics: frontend, idle, preload, web
- Language: JavaScript
- Homepage:
- Size: 2.57 MB
- Stars: 1
- Watchers: 0
- Forks: 0
- Open Issues: 14
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# Idle Preload
## Features
Preload something when the page is idle.
Idle detection algorithm:
* After page loaded, use `setTimeout` and record the real callback time delay.
* Compute the variance of multiple callback time delay.
* The page is considered idle and stable when the variance is low.
## Installation
```shell
yarn add idle-preload
```
or
```shell
npm i idle-preload --save
```
## Usage
```js
import { idlePreload } from 'idle-preload'
const preload = idlePreload({
// options
// debug: true
})
preload.push(() => {
// use your code to preload something
//
})
preload.start()
```
## Options
* `varianceLimit: Integer` (default **5**),
* `samplingCount: Integer` (default **5**),
* `afterWindowLoad: Boolean` (default **true**),
* `checkTimeInterval: Integer` (default **200**) ms,
* `debug: Boolean` (default **false**)
## License
[MIT](./LICENSE)