Skip to content

💸 Perf - Load AOS only where it's used - #4920

Draft
isaaclombardssw wants to merge 1 commit into
mainfrom
perf/4901-aos-lazy
Draft

💸 Perf - Load AOS only where it's used#4920
isaaclombardssw wants to merge 1 commit into
mainfrom
perf/4901-aos-lazy

Conversation

@isaaclombardssw

Copy link
Copy Markdown
Member

Closes #4901

What

AOS was initialised in TinaClient on every page (AOS.init + refresh in a mount effect, refreshHard on unmount), and aos/dist/aos.css was imported in 6 places, several with no data-aos elements. On a page like /events/ai-for-business-leaders — which uses none of the AOS-animated components — the library JS, its CSS and the init/measure cost were pure overhead in the hydration window.

Change

  • New components/util/aosLoader.tsx: a tiny "use client" component that dynamically imports the AOS JS in a mount effect, inits once (module-guarded) and refreshes. It carries aos/dist/aos.css as a scoped import, so the CSS only ships in the chunks of components that render it. Renders null.
  • Removed the global AOS.init / import from app/tina-client.tsx.
  • Rendered <AosLoader /> in the 9 components that actually use data-aos: testimonialsCard, youtubePlaylist, videoCards, consulting/benefits, training/presenterBlock, liveStream/liveStreamWidget, button/utilityButton, consulting/mediaCard/mediaCard, technologyCard. For utilityButton and youtubePlaylist the loader is gated on the same animated flag that toggles data-aos, so it only loads when an animation is actually requested.
  • Removed the 6 stray import "aos/dist/aos.css" lines (3 route files + ImageComponentLayout, imageTextBlock, accordionBlock, none of which have data-aos).

Kept the aos dependency — 9 components still use it, so replacing it with CSS (issue's optional step 3) is out of scope here.

Verified

  • pnpm lint (eslint) clean on changed files, prettier --check clean, tsc --noEmit no new errors (Tina client generated offline first).
  • Traced the /events/ai-for-business-leaders component graph (cardCarouselCard / ButtonRowtemplateButton, etc.) — it never reaches AosLoader, so neither the AOS JS nor CSS is in that route's bundle.
  • Runtime animation smoke-test in a browser is left for a reviewer (see below).

For a reviewer

Please eyeball the animations still fire on a testimonials page, a training/presenter page, and the live-stream widget, and confirm no "AOS is not initialised" console errors.

🤖 Generated with Claude Code

https://claude.ai/code/session_01Q8genJyZboXaa4vgYhJF4P

AOS was initialised in TinaClient on every page and its CSS imported
globally, even on pages with no data-aos elements. Move init into a small
client AosLoader that dynamically imports the AOS JS and carries the CSS,
and render it only from the 9 components that actually use data-aos. Drop
the global init and the 6 stray aos.css imports (3 pages + 3 blocks with no
data-aos).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Q8genJyZboXaa4vgYhJF4P
@github-actions

Copy link
Copy Markdown
Contributor

No linked issues found. Please add the corresponding issues in the pull request description.
Use GitHub automation to close the issue when a PR is merged

@github-actions

Copy link
Copy Markdown
Contributor

Coverage report

St.
Category Percentage Covered / Total
🔴 Statements 0.57% 267/46840
🔴 Branches 9.89% 52/526
🔴 Functions 1.26% 6/475
🔴 Lines 0.57% 267/46840

Test suite run success

19 tests passing in 2 suites.

Report generated by 🧪jest coverage report action from cd8fcfa

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

💸 Perf - Stop loading AOS on pages that don't use it

1 participant