Skip to content

Commit a6dbbca

Browse files
westonruterShyamGadde
andauthored
Merge pull request #2169 from WordPress/update/inline-scripts
Improve construction of inline scripts with `sourceURL`, hardened JSON encoding, and exporting JSON in separate script Co-authored-by: westonruter <[email protected]> Co-authored-by: ShyamGadde <[email protected]>
2 parents df16347 + b0c3686 commit a6dbbca

File tree

70 files changed

+271
-83
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

70 files changed

+271
-83
lines changed

plugins/embed-optimizer/class-embed-optimizer-tag-visitor.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ private function reduce_layout_shifts( OD_Tag_Visitor_Context $context ): void {
202202
$style_rules[] = $style_rule;
203203
}
204204

205-
$processor->append_head_html( sprintf( "<style>\n%s\n</style>\n", join( "\n", $style_rules ) ) );
205+
$processor->append_head_html( sprintf( "<style>\n%s\n/*# sourceURL=embed-optimizer-reduce-layout-shifts */\n</style>\n", join( "\n", $style_rules ) ) );
206206
}
207207
}
208208

plugins/embed-optimizer/helper.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -351,6 +351,14 @@ function embed_optimizer_get_lazy_load_script(): string {
351351
return '';
352352
}
353353

354+
$script .= sprintf(
355+
"\n//# sourceURL=%s",
356+
add_query_arg(
357+
array( 'ver' => EMBED_OPTIMIZER_VERSION ),
358+
plugins_url( embed_optimizer_get_asset_path( 'lazy-load.js' ), __FILE__ )
359+
)
360+
);
361+
354362
return $script;
355363
}
356364

plugins/embed-optimizer/tests/test-cases/all-embeds-inside-viewport/expected.html

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

plugins/embed-optimizer/tests/test-cases/nested-figure-embed/expected.html

Lines changed: 4 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

plugins/embed-optimizer/tests/test-cases/single-spotify-embed-outside-viewport-with-subsequent-script/expected.html

Lines changed: 3 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

plugins/embed-optimizer/tests/test-cases/single-twitter-embed-inside-viewport-one-group/expected.html

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

plugins/embed-optimizer/tests/test-cases/single-twitter-embed-inside-viewport/expected.html

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

plugins/embed-optimizer/tests/test-cases/single-twitter-embed-outside-viewport-on-mobile/expected.html

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

plugins/embed-optimizer/tests/test-cases/single-twitter-embed-outside-viewport/expected.html

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

plugins/embed-optimizer/tests/test-cases/single-wordpress-tv-embed-inside-viewport/expected.html

Lines changed: 3 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)