-
Notifications
You must be signed in to change notification settings - Fork 384
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
Remove duplicate and unused AMP component scripts from the response #3489
Comments
Hi @westonruter, Would the duplicate component scripts, like in the screenshot above, be output with an amp_post_template_head hook, like this? add_action(
'amp_post_template_head',
function() {
// Echo component scripts here.
}
); It looks like the recommended way of adding component scripts won't normally have duplicates. Thanks, Weston! |
@kienstra Sorry for the delay. They could be added in that way, yes, but this won't be the concern in this issue at the moment. Handling scripts added in Reader mode would be fixed as part of #2202, as the entire document would be then sent through the post-processor. So for this issue, focus on scripts that are added in Standard/Transitional mode. That means scripts that are added at the |
Thanks, @westonruter! No problem, I didn't expect or need a quick response, with the stable release and WCUS this past week. |
I'm currently working on this and I'll do two separate PRs, as both the implementation as well as the ramifications are different for the two cases enumerated above. |
The other PR would be about removing the duplicates? It seems to me that the existing PR could include the de-duplication as well. |
The thinking was that removing duplicates is a no-brainer, always fixing and never breaking. However, removing unused AMP scripts is more complicated and could potentially lead to us automatically breaking an otherwise working page, because we're missing something. Therefore, splitting this into two PRs would mean we'll be able to merge one either way, while the other might need to be put on hold. |
Verified in QA |
Feature description
If you include more than one copy of an AMP component script on a page, e.g.
amp-form
, then the validator gives a warning:In the same way, if there are scripts on the page which are not used, a validation error is also raised:
These issues come up often in the Reader mode templates which don't send the entire templates through the post-processor (which will be fixed in #2202), but it can also happen in Standard/Transitional mode when duplicate scripts are manually output in
wp_head
orwp_footer
actions (which normally should not be done since the plugin adds them already).Cf. #3253 (comment)
Do not alter or remove anything below. The following sections will be managed by moderators only.
Acceptance criteria
Implementation brief
The
AMP_Theme_Support::ensure_required_markup()
method is passed a list of$script_handles
for the AMP scripts that are required to be in the page. If those scripts are not already present in the DOM, then they are added:amp-wp/includes/class-amp-theme-support.php
Lines 1730 to 1746 in 394b202
There are two things missing here:
$script_handles
then they should be removed, as otherwise there can be an AMP validation error (as they are unused).QA testing instructions
Demo
Changelog entry
The text was updated successfully, but these errors were encountered: