-
-
Notifications
You must be signed in to change notification settings - Fork 8.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
perf(core): move scripts to document head + defer #8081
Conversation
✅ [V2]
To edit notification comments on pull requests, go to your Netlify site settings. |
⚡️ Lighthouse report for the deploy preview of this PR
|
Done 🙌 |
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
Extremely sorry my thought might misleading 🥺 |
Leaving it to @slorber for a decision... |
Regarding preload of stylesheet -: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
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 ( |
Related discussion -: vercel/next.js#24938 |
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 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 🤷♂️ |
Hi, Sorry if I am wrong |
This is inspired from
Next.js
.