barba-js
Skill4 starsChanged 4 months agoMITView on GitHub
Use Barba.js for Layer 0 in the Cinematic Web Engine (SK-096): smooth page transitions in Multi-Page Architecture (MPA) sites. Barba.js intercepts link clicks, fetches the next page via XHR, and swaps a container element — creating SPA-like transitions on traditional server-rendered sites. CRITICAL: Barba.js is MPA-only. It is NOT compatible with: - Next.js (App Router or Pages Router) - React SPAs (React Router, TanStack Router) - Any client-side routed framework For SPAs/Next.js, use instead: - <ViewTransition> component (React 19+ /…
- Installs packages
3 other projects use a version of this.
Adopted by
Most recently taken up by
- xenodeve/xeno-skillstheir own version, first seen Sep 26, 2026
- SkotAlexsander/skillstheir own version, first seen Sep 16, 2026
- freshtechbro/claudedesignskillstheir own version, first seen Oct 25, 2025
Other versions3 projects use a version of this.
Word for word · 0
None found.
Edited · 0
None found.
Wrote their own version · 3
- freshtechbro/claudedesignskills★ 975same name
- xenodeve/xeno-skills★ 2same name
- SkotAlexsander/skills★ 1same name
How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.
In this repository162 other files it gives its agents.
- agents/AGENTS.mdAGENTS.md
- skills/compound-engineering/AGENTS.mdAGENTS.md
- skills/trailofbits-security/AGENTS.mdAGENTS.md
- CLAUDE.mdCLAUDE.md
- examples/CLAUDE.mdCLAUDE.md
- skills/compound-engineering/CLAUDE.mdCLAUDE.md
- skills/trailofbits-security/CLAUDE.mdCLAUDE.md
- app-store-reviewSkill
- advanced-javascriptSkill
- ai-native-uiSkill
- anime-jsSkill
- app-l100Skill
- brand-guidelinesSkill
- cinematic-web-engineSkill
- codebase-knowledge-graphSkill
- crossplatform-monorepoSkill
- css-first-uiSkill
- design-auditSkill
- design-critiqueSkill
- dev-cycleSkill
- device-hardware-bridgeSkill
- discovery-docSkill
- docxSkill
- edge-intelligenceSkill
- graph-aware-reviewSkill
- linkedin-posterSkill
- local-first-architectureSkill
- modern-build-pipelineSkill
- motion-nativeSkill
- nano-bananaSkill
- playwrightSkill
- pptxSkill
- project-initSkill
- remotionSkill
- sensory-nativeSkill
- spline-3dSkill
- streaming-cacheSkill
- tanstack-ecosystemSkill
- design-taste-frontendSkill
- tauri-desktopSkill
- threejsSkill
- transition-nativeSkill
- ui-design-stackSkill
- visual-nativeSkill
- web-l100Skill
- web-platform-apisSkill
- xlsxSkill
- better-authSkill
- claude-real-videoSkill
- clone-websiteSkill
- css-keyframe-animationsSkill
- design-checkSkill
- design-dnaSkill
- design-polishSkill
- drizzle-neonSkill
- fastlaneSkill
- angular-architectSkill
- api-designerSkill
- architecture-designerSkill
- atlassian-mcpSkill
- The first 60 shown.
The file
We split this skill into the rules it gives an agent
10 rules. 0 are common, 2 are distinctive, and 8 are very specific to this project.
0
Common
Most of the 3 edited versions we read keep these.
2
Distinctive
This author's own choices. Worth a look.
8
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 13
Use Barba.js for Layer 0 in the Cinematic Web Engine (SK-096): smooth page transitions in Multi-Page Architecture (MPA) sites.
- Very specific: line 293
All hooks receive { current, next, trigger } data object.
- Very specific: line 320
Always kill ScrollTriggers and GSAP tweens in leave or beforeLeave
- Very specific: line 321
Always reset scroll position in afterEnter (window.scrollTo(0, 0))
- Distinctive: line 322
Always destroy and recreate Lenis on page transition
- Very specific: line 323
Use @barba/prefetch for perceived performance improvement
- Distinctive: line 324
Keep transitions under 800ms total — users notice delays beyond this
- Very specific: line 325
Use data-barba-prevent on download links, external links, and auth pages
- Very specific: line 329
Use Barba.js in a React/Next.js/SPA project — use ViewTransition API instead
- Very specific: line 333
Use both leave and once transitions without testing the initial page load
“Common” is measured: kept by at least 6 in 10 of the 3 edited versions of this file we could read. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
<!--
id: SK-094
name: barba-js
description: Barba.js page transitions — MPA smooth transitions, GSAP orchestration, view lifecycle, prefetch, cross-page animation choreography
keywords: barba, page-transition, mpa, smooth-transition, view-lifecycle, prefetch, cross-page, pjax, history-api, leave-enter
version: 1.0.0
-->Barba.js Page Transitions
When to Use This Skill
Use Barba.js for Layer 0 in the Cinematic Web Engine (SK-096): smooth page transitions in Multi-Page Architecture (MPA) sites. Barba.js intercepts link clicks, fetches the next page via XHR, and swaps a container element — creating SPA-like transitions on traditional server-rendered sites.
CRITICAL: Barba.js is MPA-only. It is NOT compatible with:
- Next.js (App Router or Pages Router)
- React SPAs (React Router, TanStack Router)
- Any client-side routed framework
For SPAs/Next.js, use instead:
<ViewTransition>component (React 19+ / Next.js 15+) — see SK-054- Motion
AnimatePresence— see SK-047 - View Transitions API (native browser) — see SK-054
Good fit for: Static sites (Astro, 11ty, Hugo), WordPress, PHP sites, vanilla HTML/JS sites, agency portfolio sites.
Installation
npm install @barba/core @barba/prefetchOptional: @barba/css for CSS-only transitions (no JS needed).
Core Concepts
<!-- Required DOM structure -->
<body>
<!-- Wrapper: persists across pages -->
<div data-barba="wrapper">
<nav><!-- Navigation persists --></nav>
<!-- Container: gets swapped on transition -->
<main data-barba="container" data-barba-namespace="home">
<!-- Page content -->
</main>
</div>
</body>- Wrapper (
data-barba="wrapper"): The persistent outer element. Never animated. - Container (
data-barba="container"): The content that gets swapped. This is what you animate. - Namespace (
data-barba-namespace): Identifies the page type for per-page transitions.
Basic Setup
import barba from '@barba/core';
barba.init({
transitions: [{
leave({ current }) {
// Animate current page out — return a Promise or GSAP timeline
return gsap.to(current.container, { opacity: 0, duration: 0.5 });
},
enter({ next }) {
// Animate next page in
return gsap.from(next.container, { opacity: 0, duration: 0.5 });
},
}],
});GSAP Orchestration (Primary Pattern)
The canonical pattern: return GSAP timelines from Barba hooks.
import barba from '@barba/core';
import gsap from 'gsap';
import { ScrollTrigger } from 'gsap/ScrollTrigger';
gsap.registerPlugin(ScrollTrigger);
barba.init({
transitions: [{
name: 'fade-slide',
leave({ current }) {
// 1. Kill all ScrollTriggers before page leaves
ScrollTrigger.getAll().forEach(t => t.kill());
// 2. Animate out — return timeline (Barba waits for it)
const tl = gsap.timeline();
tl.to(current.container, { opacity: 0, y: -30, duration: 0.4, ease: 'power2.in' });
return tl;
},
enter({ next }) {
// 3. Animate in
const tl = gsap.timeline();
tl.from(next.container, { opacity: 0, y: 30, duration: 0.6, ease: 'power3.out' });
return tl;
},
afterEnter() {
// 4. Re-initialize page-specific animations
window.scrollTo(0, 0);
ScrollTrigger.refresh();
},
}],
});Critical: ScrollTrigger Cleanup
Always kill ScrollTriggers on page leave. Stale triggers from the previous page will cause layout issues and memory leaks.
leave({ current }) {
// Kill ALL ScrollTriggers
ScrollTrigger.getAll().forEach(t => t.kill());
// Kill all GSAP tweens
gsap.killTweensOf('*');
return gsap.to(current.container, { opacity: 0, duration: 0.4 });
},Lenis Integration
Destroy and recreate Lenis on each page transition:
import Lenis from 'lenis';
let lenis;
function initLenis() {
lenis = new Lenis();
lenis.on('scroll', ScrollTrigger.update);
gsap.ticker.add((time) => lenis.raf(time * 1000));
gsap.ticker.lagSmoothing(0);
}
barba.init({
transitions: [{
leave({ current }) {
// Destroy Lenis before page leave
lenis?.destroy();
ScrollTrigger.getAll().forEach(t => t.kill());
return gsap.to(current.container, { opacity: 0, duration: 0.4 });
},
afterEnter() {
// Recreate Lenis for new page
window.scrollTo(0, 0);
initLenis();
// Initialize page-specific animations here
},
}],
});
// Initial page load
initLenis();Named Transitions
Route-specific transitions using from/to namespace rules:
barba.init({
transitions: [
{
name: 'home-to-project',
from: { namespace: ['home'] },
to: { namespace: ['project'] },
leave({ current }) {
return gsap.timeline()
.to('.grid-item', { scale: 0.8, opacity: 0, stagger: 0.05 })
.to(current.container, { opacity: 0 }, '-=0.2');
},
enter({ next }) {
return gsap.timeline()
.from(next.container, { opacity: 0 })
.from('.project-hero', { y: 100, opacity: 0, duration: 0.8 }, '-=0.3');
},
},
{
name: 'default',
// Fallback for all other routes
leave({ current }) {
return gsap.to(current.container, { opacity: 0, duration: 0.3 });
},
enter({ next }) {
return gsap.from(next.container, { opacity: 0, duration: 0.3 });
},
},
],
});View Lifecycle
Per-page initialization using views:
barba.init({
views: [
{
namespace: 'home',
beforeEnter() {
// Runs before enter transition
},
afterEnter() {
// Initialize home-specific JS (carousels, scroll animations, etc.)
initHomeAnimations();
},
beforeLeave() {
// Cleanup before leaving home
destroyHomeAnimations();
},
},
{
namespace: 'about',
afterEnter() {
initAboutAnimations();
},
},
],
transitions: [/* ... */],
});Prefetch Plugin
Prefetch pages on link hover for near-instant transitions:
import barba from '@barba/core';
import barbaPrefetch from '@barba/prefetch';
barba.use(barbaPrefetch);
barba.init({
// prefetch is now active — pages are fetched on hover
transitions: [/* ... */],
});CSS Transitions (No JS)
For simple transitions without JavaScript:
import barba from '@barba/core';
import barbaCss from '@barba/css';
barba.use(barbaCss);
barba.init({
transitions: [{
name: 'fade',
// CSS classes are automatically added/removed:
// .fade-leave, .fade-leave-active, .fade-leave-to
// .fade-enter, .fade-enter-active, .fade-enter-to
}],
});.fade-leave-active,
.fade-enter-active {
transition: opacity 0.5s ease;
}
.fade-leave-to,
.fade-enter {
opacity: 0;
}Hooks Reference
| Hook | Timing | Use For |
beforeLeave | Before leave animation | Cleanup, kill animations |
leave | Leave animation | Animate current page out |
afterLeave | After leave completes | Remove event listeners |
beforeEnter | Before enter animation | Prepare next page DOM |
enter | Enter animation | Animate next page in |
afterEnter | After enter completes | Initialize page JS, scroll reset |
All hooks receive { current, next, trigger } data object.
Preventing Links
<!-- Barba ignores these -->
<a href="/file.pdf" data-barba-prevent>Download PDF</a>
<a href="/external" data-barba-prevent="self">External</a>
<!-- Entire section -->
<div data-barba-prevent="all">
<a href="/link1">Ignored</a>
<a href="/link2">Ignored</a>
</div>Limitations
- No React/Next.js/SPA compatibility — Barba manages routing, conflicts with client-side routers
- Analytics re-firing — Must manually trigger page views in
afterEnter - Script re-execution — Inline
<script>tags in the new page don't auto-execute; use view lifecycle hooks - Third-party widgets — May need reinitialization (chat widgets, embeds, etc.)
- Low maintenance — Functionally complete but last npm publish was ~2 years ago
- Small community — ~491 GitHub stars; limited recent community content
Best Practices
- Always kill ScrollTriggers and GSAP tweens in
leaveorbeforeLeave - Always reset scroll position in
afterEnter(window.scrollTo(0, 0)) - Always destroy and recreate Lenis on page transition
- Use
@barba/prefetchfor perceived performance improvement - Keep transitions under 800ms total — users notice delays beyond this
- Use
data-barba-preventon download links, external links, and auth pages
Do Not
- Use Barba.js in a React/Next.js/SPA project — use ViewTransition API instead
- Forget to kill ScrollTriggers on page leave — causes memory leaks and broken layouts
- Animate the wrapper element — only animate containers and their children
- Skip
afterEnterinitialization — page-specific JS won't run - Use both
leaveandoncetransitions without testing the initial page load
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

