fix(perf): BIT-28145 article page TBT 7416ms -> sanitize oEmbed HTML #47

Merged
spark merged 1 commits from fix/BIT-28145-article-tbt into main 2026-08-05 19:01:41 +01:00
Owner

Summary

  • Root cause: WordPress oEmbed HTML in article body (style/link tags, inline event handlers, heavy iframes, unlazy images) was driving Total Blocking Time to 7416ms on article pages vs 73ms on home (Lighthouse Performance 60 vs target >=90).
  • Fix: strip <style>/<link> blocks and inline on* handlers from sanitized article HTML, replace <iframe> embeds with click-to-load placeholders, add loading="lazy"/decoding="async" to images, and content-visibility: auto on .article-body.

Test plan

  • 28 bridge sanitizer tests pass (new coverage: style/link/event-handler stripping, iframe placeholders, image lazy loading)
  • 47 frontend tests pass
  • Astro build succeeds
  • Deploy + re-run Lighthouse to confirm Performance >= 90 on article pages (post-merge)
  • Flush/expire Bridge Redis cache for previously-cached article HTML in production (post-merge)

Related: BIT-28130 (measurement), BIT-28145 (this issue).

## Summary - Root cause: WordPress oEmbed HTML in article body (style/link tags, inline event handlers, heavy iframes, unlazy images) was driving Total Blocking Time to 7416ms on article pages vs 73ms on home (Lighthouse Performance 60 vs target >=90). - Fix: strip `<style>`/`<link>` blocks and inline `on*` handlers from sanitized article HTML, replace `<iframe>` embeds with click-to-load placeholders, add `loading="lazy"`/`decoding="async"` to images, and `content-visibility: auto` on `.article-body`. ## Test plan - [x] 28 bridge sanitizer tests pass (new coverage: style/link/event-handler stripping, iframe placeholders, image lazy loading) - [x] 47 frontend tests pass - [x] Astro build succeeds - [ ] Deploy + re-run Lighthouse to confirm Performance >= 90 on article pages (post-merge) - [ ] Flush/expire Bridge Redis cache for previously-cached article HTML in production (post-merge) Related: BIT-28130 (measurement), BIT-28145 (this issue).
spark added 1 commit 2026-08-05 18:36:28 +01:00
fix(perf): article TBT 7416ms — strip scripts/styles/iframes/event-handlers, lazy-load images, content-visibility
Tests / bridge tests (push) Successful in 40s
Tests / writer-pipeline tests (push) Successful in 50s
Tests / frontend lib tests (push) Successful in 1m42s
Tests / writer-pipeline tests (pull_request) Successful in 1m21s
Tests / bridge tests (pull_request) Successful in 1m23s
Tests / frontend lib tests (pull_request) Successful in 48s
ee8405980c
BIT-28145: newsproject.bitreport.pt article template Total Blocking Time
was 7416ms (Lighthouse Performance 60) vs home 73ms (Performance 97).

Root cause: WordPress oEmbed HTML injected via set:html rendered <script>,
<style>, <link> tags, inline event handlers, and heavy <iframe> embeds
(Twitter, Instagram, YouTube) that blocked the main thread during HTML
parsing. The prior sanitizer only stripped <script> tags and added
loading=lazy to iframes — insufficient for the oEmbed payload.

Changes:
- Enhance bridge and frontend sanitizers to strip <style>, <link>,
  and inline event handlers (on* attributes) in addition to <script>
- Replace <iframe> elements with click-to-load placeholders (eliminates
  iframe document parsing cost from main thread)
- Add loading=lazy + decoding=async to <img> tags in article body
- Add content-visibility:auto to .article-body CSS (skip off-screen render)
- Add embed-placeholder styles in global.css + click handler in [slug].astro
- Parallelize article/related/trending bridge fetches
- Add preconnect hints for gravatar and featured images
- Document root cause in PERFORMANCE_BASELINE.md

Paperclip-Agent: Miguel Teixeira (urlKey miguel-teixeira; id 0f722e1a-bc3e-4381-8d98-76fa3c7aea10)
Paperclip-Issue: BIT-28145
paperclip-review-bot left a comment
Member

auto-approve: CI success (gitea_auto_approve_open_prs_once.py)

auto-approve: CI success (gitea_auto_approve_open_prs_once.py)
founding-engineer left a comment
Member

auto-approve: CI success (gitea_auto_approve_open_prs_once.py)

auto-approve: CI success (gitea_auto_approve_open_prs_once.py)
devops-engineer left a comment
Member

auto-approve: CI success (gitea_auto_approve_open_prs_once.py)

auto-approve: CI success (gitea_auto_approve_open_prs_once.py)
spark scheduled this pull request to auto merge when all checks succeed 2026-08-05 19:01:39 +01:00
spark merged commit 5fd457a75d into main 2026-08-05 19:01:41 +01:00
Sign in to join this conversation.