-
Notifications
You must be signed in to change notification settings - Fork 131
Use custom script type for lazy-loaded scripts #983
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
Use custom script type for lazy-loaded scripts #983
Conversation
Nice catch on the WP-Rocket usage, that makes a stronger argument for this approach. Good idea to ensure this is compatible with existing optimizers. |
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.
To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
if ( $p->get_attribute( 'type' ) ) { | ||
$p->set_attribute( 'data-original-type', $p->get_attribute( 'type' ) ); | ||
} | ||
$p->set_attribute( 'type', 'text/x.lazy-loaded-javascript' ); |
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.
Should this match the plugin name? maybe something like text/embed-optimizer
?
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.
I tried to follow the rules outlined in https://en.wikipedia.org/wiki/Media_type
That said, what about application/vnd.embed-optimizer.javascript
?
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.
Committed this in 39d4488
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.
Looks good, left one suggestion for the type name
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.
Fine!
Summary
This is a sub-PR of #982. Review/merge it first.This implements the following #979 (comment):
Another important reason so do this change is that plugins that concatenate scripts may erroneously attempt to concatenate the empty
script[data-lazy-embed-src]
scripts. By using a custom type, this will be avoided.I also just checked with WP Rocket, and they also use a custom type. The logic also looks like it would by default try to delay
script[data-lazy-embed-src]
scripts which would break Embed Optimizer. Also, the WP RocketCombine
logic specifically skips over anyscript
that has atype
that isn't JavaScript. So it seems we'd be safer in both cases to use a customtype
.Checklist
[Focus]
orInfrastructure
label.[Type]
label.no milestone
label.