Facilitate marking script/style dependencies as being covered by AMP dev mode #4598
Labels
Developer Tools
Enhancement
New feature or improvement of an existing one
Groomed
P1
Medium priority
Punted
Validation
WS:Core
Work stream for Plugin core
Feature description
Originally discussed in google/site-kit-wp#505 (comment).
The Site Kit plugin currently marks scripts for being as part of dev mode by:
/*googlesitekit*/
to the inline script content.//script[ contains( text(), "googlesitekit" ) ]
to theamp_dev_mode_element_xpaths
.This works but it is not the best developer experience, nor is it the most robust. It depends on injecting a unique string into the scripts which serves no purpose other than for marking content for dev mode. It also slows down the post-processor a bit by requiring XPath to query for the
script
elements to add thedata-ampdevmode
attribute to.For non-inline scripts, marking scripts for dev mode requires either making it a dependency of
admin-bar
, or to addscript_loader_tag
/style_loader_tag
filters to inject thedata-ampdevmode
attribute. This is also not the best developer experience.A much better experience for flagging scripts for dev mode would by to attach data to the script (or style). For example:
When this
ampdevmode
data is attached to a dependency, this can be looked for in thescript_loader_tag
/style_loader_tag
as a signal to add thedata-ampdevmode
attribute, instead of just relying on the handle being a dependency ofadmin-bar
.Not all
script
andstyle
tags are filterable, however. Namely, styles added viawp_add_inline_style()
and scripts added viawp_localize_script()
get printed directly and are not filterable. (Scripts added viawp_add_inline_script()
do get passed through thescript_loader_tag
filter). For these, we'll need rely on the post-processor to inject thedata-ampdevmode
attributes. This entails adding new XPath queries via theamp_dev_mode_element_xpaths
filter forAMP_Dev_Mode_Sanitizer
.In the end, all scripts and styles—whether external or inline—should automatically have the
data-ampdevmode
attribute added to them when the underlying registered script/style dependency has theampdevmode
data added to them.Do not alter or remove anything below. The following sections will be managed by moderators only.
Acceptance criteria
Implementation brief
QA testing instructions
Demo
Changelog entry
The text was updated successfully, but these errors were encountered: