Eliminate Render-Blocking Scripts
A classic <script> in the head stops the parser dead: no HTML after it is rendered until it downloads and executes. Moving it off the critical path is often a half-second of LCP for free.
Procedure
List every script tag that ships in the initial response:
curl -s https://shop.example.com/ | grep -oE '<script[^>]*>' | head -50Classify each:
deferruns after parsing in document order;asyncruns whenever it arrives;type="module"is deferred by default. Only scripts that write todocumentbefore parse need to stay synchronous, and almost none do.Rewrite parser-blocking tags:
<script src="/analytics.js" defer></script> <script src="/cart.js" type="module"></script>Check for
document.writecalls injected by third parties; those forbid defer and are the genuine blockers. Load them behind a consent/interaction gate instead.Measure coverage to confirm what the critical path actually executes:
# DevTools: Cmd+Shift+P -> "Coverage" -> record a reload, sort by unused bytesRe-test the initial HTML for remaining tags without
defer/async/type=module; the grep should return zero matches for your own bundles.
Pitfalls
- Deferring a script that another synchronous script assumes already ran, breaking load order silently.
- Marking a script
asyncwhen it depends on the DOM being parsed;asynccan run before the body exists. - Leaving an inline configuration script that
document.writes the loader for a tag manager; that single tag blocks everything after it. - Assuming
deferhelps a script that is already at the end of<body>; the win there is zero and the diff is noise. - Forgetting that deferred scripts still execute before
DOMContentLoaded, so a slow one delays that event.
Verification
curl -s https://shop.example.com/ | grep -cE '<script(?![^>]*(defer|async|type="module"))[^>]*src='
Zero matches means no parser-blocking external scripts remain. Report the count before and after, and the LCP delta from a throttled Lighthouse run.