Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/pladaria/requestidlecallback-polyfill
requestIdleCallback Polyfill
https://github.com/pladaria/requestidlecallback-polyfill
Last synced: about 2 months ago
JSON representation
requestIdleCallback Polyfill
- Host: GitHub
- URL: https://github.com/pladaria/requestidlecallback-polyfill
- Owner: pladaria
- Created: 2018-10-28T11:06:17.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2023-05-03T22:19:10.000Z (over 1 year ago)
- Last Synced: 2024-10-31T02:19:30.053Z (2 months ago)
- Language: JavaScript
- Size: 6.84 KB
- Stars: 32
- Watchers: 2
- Forks: 3
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# requestIdleCallback polyfill
Simple polyfill and d.ts for
[requestIdleCallback](https://developer.mozilla.org/en-US/docs/Web/API/Window/requestIdleCallback).From [MDN](https://developer.mozilla.org/en-US/docs/Web/API/Window/requestIdleCallback):
> The `window.requestIdleCallback()` method queues a function to be called during a browser's idle periods.
> This enables developers to perform background and low priority work on the main event loop, without
> impacting latency-critical events such as animation and input response. Functions are generally called in
> first-in-first-out order; however, callbacks which have a timeout specified may be called out-of-order if
> necessary in order to run them before the timeout elapses.> You can call `requestIdleCallback()` within an idle callback function to schedule another callback to take
> place no sooner than the next pass through the event loop.## Install
`npm i requestidlecallback-polyfill`
or
`yarn add requestidlecallback-polyfill`
## Usage
```js
import 'requestidlecallback-polyfill';// ...
window.requestIdleCallback(doSomething, {timeout: 2000});
```## Credits
- Code from
[developers.google.com](https://developers.google.com/web/updates/2015/08/using-requestidlecallback)
- Type definitions from
[rhysd/Mstdn](https://github.com/rhysd/Mstdn/blob/master/typings/request-idle-callback.d.ts)## License
- Code: [Apache License 2.0](https://www.apache.org/licenses/LICENSE-2.0)
- Type definitions: [MIT](https://opensource.org/licenses/MIT)