perf(core): preload stylesheets and defer scripts
This is inspired from Next.js.
[V2]
| Name | Link |
|---|---|
| Latest commit | 4e33181db211940ed713b652b6a084482e11f10e |
| Latest deploy log | https://app.netlify.com/sites/docusaurus-2/deploys/6348139f3b304500094af750 |
| Deploy Preview | https://deploy-preview-8081--docusaurus-2.netlify.app |
| Preview on mobile | Toggle QR Code...Use your smartphone camera to open QR code link. |
To edit notification comments on pull requests, go to your Netlify site settings.
⚡️ Lighthouse report for the deploy preview of this PR
| URL | Performance | Accessibility | Best Practices | SEO | PWA | Report |
|---|---|---|---|---|---|---|
| / | 🟠 64 | 🟢 98 | 🟢 100 | 🟢 100 | 🟠 80 | Report |
| /docs/installation | 🟠 73 | 🟢 100 | 🟢 100 | 🟢 100 | 🟢 90 | Report |
Done 🙌
Could you explain your changes? I don't see a potential perf difference before and after.
Could you explain your changes? I don't see a potential perf difference before and after.
Hi,
I thought by preloading CSS styles (recommend by Google) for faster loading of critical assets and making JavaScript fetch request before the body tag and make it parallel with HTML parsing would improve performance.
Ref-: https://web.dev/render-blocking-resources
Additional note -: Earlier
Next.jsalso preloaded and then executed the code at end of the body I think after version 11.0.0 they made fetch request top of body using defer attribute which have better browser support thanlink:preloadEven they preload critical asset like CSS using link:preload for better FCP.

Extremely sorry my thought might misleading 🥺
Leaving it to @slorber for a decision...
Browser Support -:
<link rel="preload" />

<script defer />

Leaving it to @slorber for a decision...
Regarding preload of stylesheet -: https://web.dev/preload-critical-assets/#preloading-css-files
Please back your changes with more external links. Show me how other frameworks like Next.js, Remix and Gatsby are using defer (or not) for the script hydrating React.
I don't believe these changes improve anything, yet present a little risk
Hi, this is how next js generate html -:

I want to see the code outputing such html, and the PR that lead to switching from end-of-body scripts to head deferred scripts: this way we can understand their motivations to do this change and understand if we should follow the same path.
Yes, I expect you to do research because otherwise I'll have to do it myself 😅
I want to see the code outputing such html, and the PR that lead to switching from end-of-body scripts to head deferred scripts: this way we can understand their motivations to do this change and understand if we should follow the same path.
Yes, I expect you to do research because otherwise I'll have to do it myself 😅
Hi, by default Next js outputs this HTML (create-next-app)
I want to see the code outputing such html, and the PR that lead to switching from end-of-body scripts to head deferred scripts: this way we can understand their motivations to do this change and understand if we should follow the same path.
Yes, I expect you to do research because otherwise I'll have to do it myself 😅
@slorber
Related discussion -: https://github.com/vercel/next.js/discussions/24938
Thanks, that's a good ref ;) will read that later
Thanks, that's a good ref ;) will read that later
Ok 💪🙌
Another useful link -: https://web.dev/render-blocking-resources
How I interpret this is that @janicklas-ralph says it's better to use this for critical JS resources:
<html>
<head>
<script defer src="./react-app.js" />
</head>
<body>
<div id="react-app" />
</body>
</html>
Instead of:
<html>
<head>
<link rel="preload" href="./react-app.js" />
</head>
<body>
<div id="react-app" />
<script async src="./react-app.js" />
</body>
</html>
That makes sense to me, so I'll merge this change without backporting it so that we can see if any issue happens on our own website. It will be in 3.0 if proven successful.
Now you also suggested to do:
<head>
+ <link rel="preload" href="/assets/css/docusaurus.f54f9970.css" as="style">
<thingsInBetween/>
<link rel="stylesheet" href="/assets/css/docusaurus.f54f9970.css">
</head>
That doesn't seem useful to me: the critical CSS is already loaded quite eagerly in the header and discovered by browsers relatively early. I doubt <thingsInBetween> will lead to any significant delay in the loading of this blocking/critical CSS file.
I'll revert this preload change for now but we'll see later how to optimize CSS loading, because this critical CSS file is too large in the first place
The change looks good to me, however, I'm not sure why Chrome devtools report the loading priority as "low" instead of "high" (it was "high" previously)
Is this expected @janicklas-ralph ?
Even the Next.js site loads all scripts as low priority 🤷♂️

The change looks good to me, however, I'm not sure why Chrome devtools report the loading priority as "low" instead of "high" (it was "high" previously)
Is this expected @janicklas-ralph ?
Even the Next.js site loads all scripts as low priority 🤷♂️
Hi,
What about using fetchpriority="high" prop to priotize the first party scripts ?
https://web.dev/priority-hints/
Sorry if I am wrong