Boost: keep position-dependent inline scripts (document.write) in place when Defer JS is enabled#49545
Draft
kraftbj wants to merge 1 commit into
Draft
Boost: keep position-dependent inline scripts (document.write) in place when Defer JS is enabled#49545kraftbj wants to merge 1 commit into
kraftbj wants to merge 1 commit into
Conversation
…is enabled The Render Blocking JS (Defer Non-Essential JavaScript) module moves all script tags to the end of the document. Inline scripts that call document.write()/document.writeln() insert markup at the script's location, so moving them renders their output after the footer instead of where the block was placed (e.g. a Custom HTML block in post content). See issue #30012. Inline scripts (no src) whose body contains document.write are now tagged with the existing ignore attribute during output filtering, so they stay in their original position. Scripts already carrying the ignore attribute, external scripts (with src), and plain inline scripts are unaffected. https://claude.ai/code/session_01PgpTrtTCH4hpz6Krh3ssho
Contributor
|
Thank you for your PR! When contributing to Jetpack, we have a few suggestions that can help us test and review your patch:
This comment will be updated as you work on your PR and make changes. If you think that some of those checks are not needed for your PR, please explain why you think so. Thanks for cooperation 🤖 Follow this PR Review Process:
If you have questions about anything, reach out in #jetpack-developers for guidance! Boost plugin: No scheduled milestone found for this plugin. If you have any questions about the release process, please ask in the #jetpack-releases channel on Slack. |
Code Coverage SummaryCoverage changed in 1 file.
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #30012
Proposed changes
document.write()/document.writeln()(e.g. added via a Custom HTML block) were relocated to after the footer, so their output rendered at the bottom of the page instead of where the block was placed.<script>tags (nosrc) whose body containsdocument.writeare now tagged with the existingdata-jetpack-boost="ignore"attribute, so they execute in their original position. The check is an intentionally conservative case-insensitive substring match — a false positive merely leaves a script in place, which is the safe outcome.srcpresent, even if the inert body mentionsdocument.write), plain inline scripts (still deferred), or scripts already carrying the ignore attribute (markup untouched, no duplicate attribute).handle_output_stream()+append_script_tags()pipeline.Related product discussion/links
Does this pull request change what data or activity we track or use?
No.
Testing instructions
data-jetpack-boost="ignore".</body>.composer install --working-dir=projects/plugins/boost && cd projects/plugins/boost && vendor/bin/phpunit-select-config phpunit.#.xml.dist --bootstrap tests/bootstrap.php --testsuite unit --filter Render_Blocking_JS_Test(22 tests, 28 assertions passing; full Boostunitsuite: 120 tests, 340 assertions).https://claude.ai/code/session_01PgpTrtTCH4hpz6Krh3ssho
Generated by Claude Code