Skip to content
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

feat: defer mode #3237

Draft
wants to merge 8 commits into
base: main
Choose a base branch
from
Draft

feat: defer mode #3237

wants to merge 8 commits into from

Conversation

slorber
Copy link
Collaborator

@slorber slorber commented Aug 7, 2020

Motivation

Webpack JS assets are added to the page using defer, making them less "critical" for the browser.

As Docusaurus v2 can almost work without any JS, we can see React hydration as non-mandatory progressive enhancement

For now it's just a POC

…nhancement" of a static site that works without JS
@slorber slorber requested a review from yangshun as a code owner August 7, 2020 11:11
@facebook-github-bot facebook-github-bot added the CLA Signed Signed Facebook CLA label Aug 7, 2020
@slorber slorber added pr: new feature This PR adds a new API or behavior. pr: performance This PR does not add a new behavior, but existing behaviors will be more memory- / time-efficient. v2 and removed CLA Signed Signed Facebook CLA labels Aug 7, 2020
@slorber slorber marked this pull request as draft August 7, 2020 11:12
@docusaurus-bot
Copy link
Contributor

docusaurus-bot commented Aug 7, 2020

[V2]

Name Link
🔨 Latest commit 0423acf
🔍 Latest deploy log https://app.netlify.com/sites/docusaurus-2/deploys/624fda5d3d15550008e0395a
😎 Deploy Preview https://deploy-preview-3237--docusaurus-2.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site settings.

@mpsq
Copy link
Contributor

mpsq commented Aug 14, 2020

I am highly interested in this, I was thinking of implementing the exact same thing. Is there any drawback you can think of?

Also, it might be interesting to let the user defer the main stylesheet. One could optimise their website by inlining the critical CSS and relying on the full stylesheet later in the rendering process in order to optimise the FCP.

@slorber
Copy link
Collaborator Author

slorber commented Aug 14, 2020

Hi,

Unfortunately I'm not a perf expert. Using http://web.dev/measure I get highly variable results but I don't see any significant improvement (at least in score) by deferring the scripts, so not sure how to reliably measure that it improves anything.

If that interests you, here are 3 Docusaurus deployments I used for my tests:

No JS at all:
https://5f2d50ba7316ec0008f830a9--docusaurus-2.netlify.app/build/

JS low priority (end of body, defer)
https://5f2d4cfb5ac4740007ff0684--docusaurus-2.netlify.app/build/

JS high priority (preload + no defer)
https://5f2d193a5609540008fb969c--docusaurus-2.netlify.app/build/

If this is useful, I'd find it cool to be able to specific which one of the 3 modes you want :)

The "no js" is likely to have some issues currently but this seems fixable (can't expand sidebar categories etc...)

@mpsq
Copy link
Contributor

mpsq commented Aug 17, 2020

Hi Sébastien,

Thanks for taking the time to do that. Here are Lighthouse performance results for each page:

  1. No JS at all:
    2020-08-17-094146_grim

  2. JS low priority (end of body, defer)
    2020-08-17-094424_grim

  3. JS high priority (preload + no defer)
    2020-08-17-094331_grim

My take on the results:

  1. This is obviously the best, although FCP is higher than in 2. this is still better because the total blocking time is 0ms. That being said, this is probably not a practical solution for many Docusaurus V2 users, I am sure many people rely on client side rendering. This also breaks Algolia's search.

  2. Extremely good FCP, more than 2x faster than 3. while still keeping client side JS, this is the perfect solution IMO.

  3. Current situation, no matter was you do (I tested with: HTTP2, brotli compression, CDN and a blank page!), FCP will be mediocre at best, the blocking JS is the limiting factor.

@slorber
Copy link
Collaborator Author

slorber commented Aug 17, 2020

  1. => some users might not use the classic theme and won't necessarily have a search. If they really want the classic theme they can eventually not use the Algolia search at all, so I wouldn't see this widely used but I think it makes sense.

  2. 3). I also think 2 is theoretically better, but in my experience running tests using https://web.dev/measure/ (to not have my own computer as a bias), I get very random results, some runs get 2 better, some others get 3 better...

Maybe you could share me how you get these scores? are they consistent across multiple runs? My scores are very random , all 3 gives between 60 and 95 quite randomly so it's hard to do anything with that...

Note, React is working on progressive hydration, afaik this is not ready but this would be an interesting feature to get 3 perform better.

@mpsq
Copy link
Contributor

mpsq commented Aug 19, 2020

Yes you are right, the results are changing quite a lot between runs. I will script this and run 100 tests per version, I will keep you updated once I have the results.

I still think 2. would be a great option: no downside and bench results seem to be better, let's prove it with reliable numbers 🙂.

@slorber
Copy link
Collaborator Author

slorber commented Aug 19, 2020

Thanks :) that's something I wanted to do but didn't have time.

@mpsq
Copy link
Contributor

mpsq commented Aug 24, 2020

For 100 runs (using Lighthouse programmatically), I get:

No JS: 99.55
Defer: 96.69
Preload: 92.63

If you want to reproduce the results yourself, you can check the code on this repo.

EDIT: I re-ran the script with 100 benchmarks (50 before) per scenario and updated the results accordingly.

@mpsq
Copy link
Contributor

mpsq commented Aug 24, 2020

After 1000 runs:

No JS: 99.336
Defer: 95.886
Preload: 90.453

@github-actions
Copy link

github-actions bot commented Nov 19, 2021

⚡️ Lighthouse report for the changes in this PR:

Category Score
🟠 Performance 86
🟢 Accessibility 100
🟢 Best practices 100
🟢 SEO 100
🟠 PWA 80

Lighthouse ran on https://deploy-preview-3237--docusaurus-2.netlify.app/

@github-actions
Copy link

github-actions bot commented Nov 19, 2021

Size Change: -256 B (0%)

Total Size: 805 kB

Filename Size Change
website/build/index.html 38.3 kB -256 B (-1%)
ℹ️ View Unchanged
Filename Size
website/.docusaurus/globalData.json 49.9 kB
website/build/assets/css/styles.********.css 105 kB
website/build/assets/js/main.********.js 612 kB

compressed-size-action

yarn.lock Outdated Show resolved Hide resolved
@slorber slorber mentioned this pull request Apr 21, 2022
2 tasks
@Josh-Cena Josh-Cena changed the title feat(v2): defer mode feat: defer mode May 25, 2022
@slorber
Copy link
Collaborator Author

slorber commented Jul 18, 2022

to be continued after React 18 upgrade: we need time sliced hydration

https://twitter.com/ryanflorence/status/1547959632663961602

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed Signed Facebook CLA pr: new feature This PR adds a new API or behavior. pr: performance This PR does not add a new behavior, but existing behaviors will be more memory- / time-efficient.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants