document.write() is a legacy JavaScript pattern that can block HTML parsing and, in some cases, trigger poor loading behavior. It is often introduced by old ad tags, analytics snippets, widgets, or abandoned plugins.
Copy this as a starting pattern, then adapt paths/selectors to your real site and test before release.
// Replace document.write with explicit DOM insertion
const script = document.createElement('script');
script.src = 'https://example.com/widget.js';
script.async = true;
document.head.appendChild(script);
B · FIX WITHOUT CODE
Update or replace the plugin/app that injects the legacy snippet.
Remove abandoned ad or tracking tags from the tag manager.
Contact the third-party provider for a modern asynchronous embed.
C · ELEMENTOR / SHOPIFY / WIX
WordPress: inspect theme header/footer injections and old plugins.
Shopify: search theme.liquid and app embeds for legacy snippets.
Wix: inspect custom code injections and marketing integrations.
04 · BEFORE / AFTER PROOF
Verify the fix instead of guessing.
Verify the third-party feature still works after replacement and compare loading behavior before/after. Removing document.write alone does not guarantee a specific score gain.
BEFOREMeasure the affected URLAFTERRe-test the same URL and device class
05 · FAQ
Common questions
Is document.write always broken?
Not always, but it is legacy and can block parsing. Modern asynchronous alternatives are generally safer.
Can I just delete the snippet?
Only if you confirm the related feature, tracking, or vendor code is no longer required.