Skip to content
Defer JS work until the browser has a chance to breathe
JavaScript
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.gitignore Initial commit Sep 20, 2018
.travis.yml I like async/await in tests, so drop testing on node 6 for now Sep 21, 2018
idleish.js Make it so Sep 20, 2018
index.js Make it so Sep 20, 2018
package-lock.json Make it so Sep 20, 2018
package.json
readme.md requestIdleTimeout -> requestIdleCallback Nov 2, 2018
test.js

readme.md

idle-until-urgent

Fetch resources lazily - either whenever the browser is next idle, or when you request the resource.

In a browser that doesn't support requestIdleCallback, or in node.js where the API is not available, falls back to setTimeout(fn, 1000).

Inspired directly by this 💯 post by Philip Walton, but uses a function-based API instead of classes. It's also about a third the size of idlize/defineIdleProperty.mjs (after minification) by avoiding classes and using the dumbest possible requestIdleTimeout fallback.

Install

npm i idle-until-urgent
const makeIdleGetter = require('idle-until-urgent')

Usage

const getFormatter = makeIdleGetter(() => new Intl.DateTimeFormat('en-US', {
	timeZone: 'America/Los_Angeles',
}))

// later in your code, presumably not during the first tick...

getFormatter().format(new Date(1537452915210)) // => '9/20/2018'

License

WTFPL

You can’t perform that action at this time.