Options
All
  • Public
  • Public/Protected
  • All
Menu

Module "window/prefetch"

Index

Type aliases

PrefetchAs

PrefetchAs: "audio" | "document" | "embed" | "fetch" | "font" | "image" | "object" | "script" | "style" | "track" | "video" | "worker" | undefined

Possible values for the "as" param of prefetch function https://developer.mozilla.org/en-US/docs/Web/HTML/Element/link#attr-as

PrefetchConfiguration

PrefetchConfiguration: { body?: undefined | string; cors?: false | "anonymous" | "use-credentials"; forcePrefetchRatio?: undefined | number; includeCacheMisses?: undefined | false | true; maxAgeSeconds?: undefined | number; method?: HTTPMethod }

Object with configuration for prefetch function

Type declaration

  • Optional body?: undefined | string

    Sets the body of prefetch request.

  • Optional cors?: false | "anonymous" | "use-credentials"

    Allows to change default CORS policy of prefetch request. https://developer.mozilla.org/en-US/docs/Web/HTML/Element/link#attr-crossorigin

  • Optional forcePrefetchRatio?: undefined | number

    Allows to override the default forcePrefetchRatio value from install() function. The number represents ratio of requests that are sent to origin even when they are not in the Edge cache. Possible values: Number between 0 and 1. Number 0 is equal to 0% requests and 1 to 100% requests sent to origin.

  • Optional includeCacheMisses?: undefined | false | true

    Allows to override the default includeCacheMisses value from install() function. Set to true to send all requests to origin even when they are not in the Edge cache.

  • Optional maxAgeSeconds?: undefined | number

    Allows to override the default Prefetch TTL or serviceWorkerSeconds value defined in routes.js. The number represents the seconds for how long the item will be stored in the browser cache.

  • Optional method?: HTTPMethod

    Allows to change default HTTP GET method of prefetch request.

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

  • Configures prefetching options

    Parameters

    Returns void

maybeAddHeadParam

  • maybeAddHeadParam(url: URL): void
  • Parameters

    • url: URL

    Returns void

maybeAddThrottleParam

  • Adds the query param that indicates to the service worker that a request may be throttled

    Parameters

    Returns void

modifyUrl

prefetch

  • Prefetches and caches the specified URL.

    Example

    import { prefetch } from '@edgio/prefetch/window
    
    // Prefetches the URL with default PrefetchConfiguration
    prefetch('/some/url')
    
    // Prefetches the URL as fetch with custom PrefetchConfiguration
    prefetch('/some/url', "fetch", {
        // Overrides the default Prefetch TTL or serviceWorkerSeconds value defined in routes.js
        maxAgeSeconds: 300, // 5 minutes
    
        // Allows to override the default forcePrefetchRatio value from install() function
        includeCacheMisses: true
    });

    Parameters

    • url: string

      The URL to prefetch

    • Default value as: PrefetchAs = "fetch"

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

    • Default value config: PrefetchConfiguration = {cors: 'anonymous',includeCacheMisses: options.includeCacheMisses,forcePrefetchRatio: options.forcePrefetchRatio,}

      Options to use for the prefetch

    Returns Promise<void>

shouldAcceptThrottling

  • 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.forcePrefetchRatio

    Parameters

    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