<link rel="prefetch" href="/app/module.css">
<head>
    ...
    <link rel="prefetch" href="/app/module.js">
    <link rel="prefetch" href="/app/module.css">
    ...
</head>
<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>Incorrect Usage Example</title>
        <link rel="prefetch" href="image.jpg">
    </head>
    <body>
        <img src="image.jpg" alt="Image loaded on the current web page">
    </body>
</html>
<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>Correct Usage Example</title>
        <link rel="prefetch" href="next-page.html">
    </head>
    <body>
        <a href="next-page.html">Go to the next page</a>
    </body>
</html>
<html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>External Domain Resource Prefetch Example</title>
        <!-- When prefetching resources from an external CDN or another domain, specify the crossorigin attribute as well. -->
        <link rel="prefetch" href="https://other-domain.com/image.png" as="image" crossorigin="anonymous">
    </head>
    <body>
        <img src="https://other-domain.com/image.png" alt="External image">
    </body>
</html>
<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>Incorrect Usage Example</title>
        <link rel="prefetch" href="next-page.html">
        <!-- Duplicate prefetch request -->
        <link rel="prefetch" href="next-page.html">
    </head>
    <body>
        <a href="next-page.html">Go to the next page</a>
    </body>
</html>
<link rel="prefetch" href="page.html">
<link rel="prefetch" href="page.html">
<link rel="prefetch" href="page.css">
<link rel="prefetch" href="page.js">
<link rel="prefetch" href="page-image.jpg">
<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>Prefetching the Next Page</title>
        <link rel="prefetch" href="next-page.html">
    </head>
    <body>
        <h1>Current Page</h1>
        <a href="next-page.html">Go to the next page</a>
    </body>
</html>
<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>Optimizing Asynchronous Component Loading</title>
        <!-- Prefetch an asynchronously loaded component -->
        <link rel="prefetch" href="async-component.js">
    </head>
    <body>
        <h1>Current Page</h1>
        <p>
            To load the asynchronous component,
            click <button id="load-component">here</button>.
        </p>
        <script>
            const btn = document.getElementById("load-component");

            btn.addEventListener("click", () => {
                // Load the component asynchronously
                import("async-component.js").then(module => {
                    // Use the loaded component
                });
            });
        </script>
    </body>
</html>

Last updated:

Last updated: