• Installs the service worker and automatically prefetches all links on the page that match the rules with the 'max_age' and 'service_worker_max_age' features.

    It also immediately prefetches all URLs specified in prefetchURLs. All links whose href attribute matches one of the specified prefetchPatterns will be watched and when a matching link is visible in the viewport, the destination URL will be prefetched and added to the cache. See InstallOptions for more details.

    Example of simple installation

     import { install } from '@edgio/prefetch/window';

    // Install the service worker
    document.addEventListener('DOMContentLoaded', () => {
    install();
    });

    Example of installation with advanced config

     import { install } from '@edgio/prefetch/window';

    // Install the service worker
    document.addEventListener('DOMContentLoaded', () => {
    install({
    // Prefetches the specified URLs immediately after installation
    prefetchURLs: [
    '/some/url'
    ],
    // Watches all links on the page that match specified regex patterns and prefetches their destination URL
    // when the link becomes visible in the viewport
    prefetchPatterns: [
    //products/(.+)/
    ]
    });
    });

    Parameters

    • Optional options: Partial<default>

    Returns Promise<void>

Generated using TypeDoc