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 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'