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

Investigate moving some extension scripts to the end of <body> #327

Open
schlessera opened this issue Aug 25, 2021 · 6 comments
Open

Investigate moving some extension scripts to the end of <body> #327

schlessera opened this issue Aug 25, 2021 · 6 comments
Assignees
Labels
Optimizer P2 Low Priority

Comments

@schlessera
Copy link
Collaborator

Some extension scripts are only needed to power the interactivity for the user and are not necessary during the initial rendering process.

Moving these scripts to the end of the <body> tag instead of having them in the <head> would thus likely improve LCP.

We should investigate which extensions can safely be moved, and whether it is always a net win for CWV.

See this comment by @westonruter where he already experimented with this approach with promising results: ampproject/amp-wp#6182 (comment)

@schlessera
Copy link
Collaborator Author

schlessera commented Aug 25, 2021

@ediamin As a start, it would be great to have a configuration value for the AutoExtensions transformer that takes an array of extension names for which to move the corresponding extension scripts to the end of the <body> tag.

With such a configuration value, we'll then be able to write a small custom plugin to configure this via URL arguments for easy experimentation.

@schlessera schlessera assigned schlessera and ediamin and unassigned schlessera Aug 25, 2021
@westonruter
Copy link
Member

westonruter commented Aug 25, 2021

Here's a prototype transformer for moving non-critical scripts to the end of the body: https://gist.github.com/westonruter/e45cd802a75c7deb80a2a1639b4cea7c

@westonruter
Copy link
Member

In the context of the AMP-WP plugin, this is something we may want to enable by default if we're not targeting AMP validity (cf. ampproject/amp-wp#6546).

@schlessera
Copy link
Collaborator Author

@westonruter Was that ever discussed with the AMP team to allow for moving AMP scripts to the body? I think that should be valid, given it can improve performance AND it is not in fact custom JS.

@westonruter
Copy link
Member

Yes, some planning has gone into it but no amphtml issue has been created for it yet. It's not as simple as just making it valid as currently the runtime, validator, and optimizer are only expecting scripts in the head. cc @rcebulko @jridgewell @erwinmombay

@schlessera
Copy link
Collaborator Author

I'll look into supporting this in the PHP validator and optimizer to see what changes would be needed. I don't know enough about the runtime though to go through that as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Optimizer P2 Low Priority
Projects
None yet
Development

No branches or pull requests

3 participants