Options
All
  • Public
  • Public/Protected
  • All
Menu

Module "window/prefetch"

Index

Type aliases

PrefetchConfiguration

PrefetchConfiguration: { body?: undefined | string; cors?: false | "anonymous" | "use-credentials"; headers?: undefined | {}; method?: HTTPMethod }

Type declaration

  • Optional body?: undefined | string
  • Optional cors?: false | "anonymous" | "use-credentials"
  • Optional headers?: undefined | {}
  • Optional method?: HTTPMethod

Variables

Const MAX_URL_BYTES

MAX_URL_BYTES: number = 2 ** 13

Let options

options: PrefetchOptions = defaults

Const prefetched

prefetched: Set<unknown> = new Set()

Functions

appendSearchParam

  • appendSearchParam(url: URL, name: string, value: string): void
  • Parameters

    • url: URL
    • name: string
    • value: string

    Returns void

configure

  • configure(opts: Partial<PrefetchOptions>): void
  • Configures prefetching options

    Parameters

    • opts: Partial<PrefetchOptions>

    Returns void

maybeAddHeadParam

  • maybeAddHeadParam(url: URL): void
  • Parameters

    • url: URL

    Returns void

maybeAddPrefetchParam

  • maybeAddPrefetchParam(url: URL): void
  • Adds the query param that indicates to the service worker that a request is a prefetch.

    Parameters

    • url: URL

    Returns void

modifyUrl

prefetch

  • Prefetches and caches the specified URL.

    Example

    import { prefetch } from '@xdn/prefetch/window
    
    prefetch('/some/url')

    Parameters

    • url: string

      The URL to prefetch

    • Default value as: string = "fetch"

      Value to use for the "as" attribute of the tag

    • Default value config: PrefetchConfiguration = { cors: 'anonymous' }

      Options to use for the prefetch

    Returns Promise<void>

shouldAcceptThrottling

  • shouldAcceptThrottling(): boolean
  • Returns true if the next prefetch request should only be served from the edge cache. This is done by comparing a random number between 0 and 1 to options.forceFrefetchRatio

    Returns boolean

Object literals

Const defaults

defaults: object

cacheHost

cacheHost: undefined = undefined

forcePrefetchRatio

forcePrefetchRatio: number = 0

includeCacheMisses

includeCacheMisses: boolean = false

spaRoutes

spaRoutes: never[] = []

Generated using TypeDoc