Hey everyone ![]()
I’m coming from Sage 9 and have recently started working with Sage 11.2.1. I’m trying to get my head around the “Sage 11 way” of structuring JavaScript.
In Sage 9, I was used to something like:
resources/
└── scripts/
├── main.js
└── routes/
├── common.js
├── home.js
└── about.js
The router would use the WordPress body classes to decide which route/code to run.
From what I understand, Sage 11 doesn’t really work this way anymore. Instead, you have the Vite entrypoint (app.js) and can use ES modules/dynamic imports.
So I’m wondering how people are actually structuring this in their projects.
For example, my project needs GSAP, Lenis, swiper and Barba.js (for now)
Would you have something like:
resources/
└── scripts/
├── app.js
├── global/
│ ├── gsap.js
│ ├── lenis.js
│ └── barba.js
├── components/
│ ├── navbar.js
│ └── marquee.js
└── pages/
├── home.js
└── works.js
And then in app.js:
import './global/gsap';
import './global/lenis';
import './global/barba';
import './components/navbar';
Then load page-specific code dynamically:
if (document.body.classList.contains('home')) {
import('./pages/home.js').then(({ initHome }) => {
initHome();
});
}
But because I’m using Barba.js, I’m not sure whether the body-class approach even makes sense anymore.
I’m particularly interested in real-world Sage 11 setups rather than just the theoretical Vite approach.
How do you structure your JS when you have:
- global libraries like GSAP / Lenis
- global components like navigation
- page-specific animations
- Barba.js page transitions
- potentially large libraries that aren’t needed on every page
I’m mainly trying to understand how people are actually approaching JS architecture in real Sage 11 projects, especially when using GSAP/Lenis/Barba.
Also, if you have any good resources, articles, or real Sage 11 projects that demonstrate a solid JS structure, I’d really appreciate it. I’m coming from Sage 9, so I’m trying to get up to speed quickly without going down the wrong path.
Thanks! ![]()