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

Web page load performance #43054

Closed
adamwoodnz opened this issue Aug 8, 2022 · 13 comments
Closed

Web page load performance #43054

adamwoodnz opened this issue Aug 8, 2022 · 13 comments
Labels
[Feature] UI Components Impacts or related to the UI component system [Type] Performance Related to performance efforts

Comments

@adamwoodnz
Copy link

adamwoodnz commented Aug 8, 2022

Description

We've started performance testing of the new wordpress.org home and download pages and we're getting low Page Speed scores due to a couple of Gutenberg related issues. This Chrome DevTools waterfall and coverage report shows them:

Screen Shot 2022-08-08 at 2 55 38 PM

1. Scripts loaded in the head causing render blocking

The waterfall shows there are 9 Gutenberg scripts loaded in the head, including some large ones: react-dom, lodash, date, moment.

Screen Shot 2022-08-08 at 3 26 21 PM

Is there a reason for the plugin to load so many scripts in the head or could they be moved to the end of the body like others?

2. Unused Javascript

The coverage report shows that of the 770k for the Gutenberg components script, 74.9% of it is unused.

Is any work in progress to lazy load components as required by the webpage?

Step-by-step reproduction instructions

Visit https://wordpress.org/main-test/ and https://pagespeed.web.dev/report?url=https%3A%2F%2Fwordpress.org%2Fmain-test%2F&form_factor=mobile

Observe Gutenberg scripts being loaded in the head and associated Page Speed diagnostics and opportunities.

Screenshots, screen recording, code snippet

No response

Environment info

WordPress 6.1-alpha-53840 running WordPress.org Main Block Theme, 2022 theme.

Gutenberg 13.8.0

Google Chrome on MacOS, Google Page Speed

Please confirm that you have searched existing issues in the repo.

Yes

Please confirm that you have tested with all plugins deactivated except Gutenberg.

N/A

@adamwoodnz adamwoodnz added the [Type] Performance Related to performance efforts label Aug 8, 2022
@peterwilsoncc
Copy link
Contributor

This looks to be caused by blocks.json enqueuing scripts in the header rather than the footer. The source is within register_block_script_handle() in WordPress Core.

The site in question is using the wp.org multisite-latest-posts block as best I can tell, thus bringing all the assets to the HTML header.

@mtias
Copy link
Member

mtias commented Aug 8, 2022

@adamwoodnz the block Peter refers to is the one pulling in all those dependencies, for visibly no reason that I can tell. Not sure how that block was designed, but it seems superfluos for it to be rendered client side instead of server side given it seems to have no interactivity affordances.

@ocean90
Copy link
Member

ocean90 commented Aug 8, 2022

@TimothyBJacobs
Copy link
Member

I think this is because the theme is using the Modal component from @wordpress/components to render a modal on the download page.

https://github.com/WordPress/wporg-main-2022/blob/4279809f9e39662a176cbdd0b46ad6863655a189/source/wp-content/themes/wporg-main-2022/src/components/download-modal/DownloadModal.js

You can see that in action when you click on the Download button.

The @wordpress/components package has a lot of dependencies, and I don't think it's really meant/ready to be used on the front-end.

@adamwoodnz
Copy link
Author

Thanks for the feedback all, we'll discuss!

@adamwoodnz
Copy link
Author

I see this ticket was closed #17079 and Modal was mentioned as being one of the components that could benefit from a separate package. We also faced this problem trying to use Spinner. Any appetite to reopen now?

Modal bundles all the functionality we need so we'd really like to continue using it. For now I'm going to see if we can improve the home page performance by only loading the download modal script on the download page. Hopefully the latest news plugin doesn't also cause the components import, although I suspect moment and date will still be loaded in the head.

@TimothyBJacobs
Copy link
Member

Something you could potentially explore would be to limit the Webpack Dependency Extraction plugin to only handle @wordpress/i18n and instead let Webpack tree shake to generate a built file with only the needed JS included.

@Mamaduka
Copy link
Member

Mamaduka commented Sep 3, 2022

I think the "Multisite Latest Posts" block's front.js can be refactored with vanilla JS and remove all React dependencies. It's currently loading ReactDOM, React, Moment, and a few other Block Editor components.

@tyxla
Copy link
Member

tyxla commented Jul 13, 2023

A side note that Lodash has completely been removed - see #52571 and #17025.

@adamwoodnz adamwoodnz added the [Feature] UI Components Impacts or related to the UI component system label Jul 20, 2023
@adamwoodnz
Copy link
Author

Performance tests have improved since I posted this. Lodash removal is a definite win. We've now removed the modal code from the home page and only load it on /downloads. I'm yet to experiment with deferring scripts or tree shaking.

@mtias
Copy link
Member

mtias commented Aug 7, 2023

@adamwoodnz can this issue be closed? It seems that remaining work is more about optimizations on the wordpress.org website side.

@adamwoodnz
Copy link
Author

@adamwoodnz can this issue be closed? It seems that remaining work is more about optimizations on the wordpress.org website side.

Yeah I think that's fair. I still think it would be great for the general usability and widespread adoption of @wordpress/components as a UI library, if components like Spinner, Modal, etc. could be imported separately without the full weight of the package, as suggested on #17079

@mtias
Copy link
Member

mtias commented Aug 8, 2023

They are not really designed for frontend use cases, though.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] UI Components Impacts or related to the UI component system [Type] Performance Related to performance efforts
Projects
None yet
Development

No branches or pull requests

7 participants