Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how do you tell if resources are being preloaded in browser developer console

I am using <link rel="preload" ...> technique to make the resources load faster, but I'm not seeing a measurable effect on page load times. I'm not sure if this is because the resources are not actually being preloaded, or for some other reason.

If I'm using Firefox to debug, how do I determine in the Firefox Developer Console whether a resource was preloaded?

like image 544
Daniel Kats Avatar asked Aug 09 '19 16:08

Daniel Kats


People also ask

Which attribute indicates whether a resource should preload or not?

Preloading Web fonts # The crossorigin attribute indicates whether the resource should be fetched with a CORS request as the font may come from a different domain. Without this attribute, the preloaded font is ignored by the browser.

Should you preload CSS files?

Preloading your CSS (and other external resources) helps the page load quicker.

How does Preload work?

<link rel="preload"> tells the browser to download and cache a resource (like a script or a stylesheet) as soon as possible. It's helpful when you need that resource a few seconds after loading the page, and you want to speed it up. The browser doesn't do anything with the resource after downloading it.

What is preload and prefetch?

Preload is an early fetch instruction to the browser to request a resource needed for a page (key scripts, Web Fonts, hero images). Prefetch serves a slightly different use case — a future navigation by the user (e.g between views or pages) where fetched resources and requests need to persist across navigations.


1 Answers

Preloading resources only has a measurable effect if the <link rel="preload" ...> and the actual request of the resource are "far apart" from each other. E.g. if you want to preload a CSS style sheet but have the <link rel="stylesheet" ...> right after the <link rel="preload" ...>, you probably won't see any difference. It may be different when there is a resource within that stylesheet that you want to preload.

Furthermore, you need to ensure that the syntax of the preload is correct. For the preload to work, you have to specify two more attributes besides rel, href to define the source to preload and as to specify the type of resource.

See the description of <link> and the one for how to preload content on MDN for more info on that.

To check whether preloading has any influence on performance, you should have a look at times and the order of the resources being loaded within the DevTools Network Monitor.

Having said that, preloading actually does not work in Firefox yet (as of version 68). According to bug 1222633 it's implemented since Firefox 56, but there are some things like preloading resources marked with no-cache header which still need to be implemented. Checking the advanced options in about:config there is a preference network.preload, which controls preloading but is set to false by default. Also, the aforementioned MDN pages mention that this feature was disabled due to some issues.

Here's a simple test for whether preloading works in your browser:

<!DOCTYPE html>
<html>
    <head>
        <link rel="preload" href="image.jpg" as="image" type="image/jpeg"/>
        <script>
        for (var i=0; i < 10000000000; i++) {
            var x = i;
        }
        window.addEventListener("DOMContentLoaded",
            e => document.body.style.backgroundImage = 'url(image.jpg)'
        );
        </script>
    </head>
    <body>
    </body>
</html>

If preloading is supported, the request for the image should be made before the JavaScript gets executed, i.e. you should see the request for the image immediately after the one for the HTML document is done.

like image 195
Sebastian Zartner Avatar answered Sep 27 '22 20:09

Sebastian Zartner