💸 Perf - Load AOS only where it's used - #4920
Draft
isaaclombardssw wants to merge 1 commit into
Draft
Conversation
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
Contributor
|
No linked issues found. Please add the corresponding issues in the pull request description. |
Contributor
Coverage report
Test suite run success19 tests passing in 2 suites. Report generated by 🧪jest coverage report action from cd8fcfa |
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.
Closes #4901
What
AOS was initialised in
TinaClienton every page (AOS.init+refreshin a mount effect,refreshHardon unmount), andaos/dist/aos.csswas imported in 6 places, several with nodata-aoselements. 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
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 carriesaos/dist/aos.cssas a scoped import, so the CSS only ships in the chunks of components that render it. Rendersnull.AOS.init/ import fromapp/tina-client.tsx.<AosLoader />in the 9 components that actually usedata-aos:testimonialsCard,youtubePlaylist,videoCards,consulting/benefits,training/presenterBlock,liveStream/liveStreamWidget,button/utilityButton,consulting/mediaCard/mediaCard,technologyCard. ForutilityButtonandyoutubePlaylistthe loader is gated on the sameanimatedflag that togglesdata-aos, so it only loads when an animation is actually requested.import "aos/dist/aos.css"lines (3 route files +ImageComponentLayout,imageTextBlock,accordionBlock, none of which havedata-aos).Kept the
aosdependency — 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 --checkclean,tsc --noEmitno new errors (Tina client generated offline first)./events/ai-for-business-leaderscomponent graph (cardCarousel→Card/ButtonRow→templateButton, etc.) — it never reachesAosLoader, so neither the AOS JS nor CSS is in that route's bundle.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