API reference

Glacier.prefetch()

prefetch() warms a specific entry on demand. Use it when you know something will be needed soon and don't want to wait for Glacier's predictor to figure that out.


Signature

glacier.prefetch(
  key: string,
  ...args: any[]
): Promise<void>

It triggers the registered loader for key with the given arguments and stores the result, but resolves with void — you're warming the cache, not reading from it.

Parameters

  • key — the key of a query previously registered with predict().
  • args — the arguments to warm for, matching the loader's signature.

Example

A common pattern is prefetching on intent — for instance, when a user hovers a link:

import { glacier } from '../glacier.config'

function onHover(postId) {
  // Warm the detail view before the click lands
  glacier.prefetch('post', postId)
}

By the time the navigation happens, the data is already cached and the page renders instantly.

Prefetch is fire-and-forget

prefetch() intentionally swallows loader errors so a failed warm never breaks your UI — the data simply stays cold and is fetched normally on the real request. If you need to handle the error, call the predicted function directly instead.

When to use it

Reach for prefetch() when you have explicit knowledge the predictor doesn't: hover intent, a wizard's next step, or data you know a background job will need. For everything else, let predict() warm things automatically.

Previous
Glacier.predict()