barba.js [v2]
Barba.js is a small (7kb minified and compressed) and easy-to-use library that helps you creating fluid and smooth transitions between your website’s pages.
It helps reducing the delay between your pages, minimizing browser HTTP requests and enhancing your user’s web experience.
Notice: this guide assumes intermediate level knowledge of HTML, CSS, and JavaScript. It is worth mentioning that all the code examples use ES6+ syntax. If you are not comfortable with, we encourage you to grasp the basics then come back.
In case of emergency, check this “legacy” code example.
Useful links
- User guide
- @barba/core
- @barba/router
- @barba/prefetch
- @barba/css
- @barba/head (coming soon)
- @barba/preset (coming soon)
- API documentation
- Github repo
- Slack channel
Install
Using npm:
1 | npm install @barba/core |
or using yarn:
1 | yarn add @barba/core |
or using a CDN:
1 | <script src="https://unpkg.com/@barba/core"></script> |
Getting started
See @barba/core for more details…
1 | // do not import Barba like this if you load the library through the browser |
Browser support
Barba.js can be viewed as a progressive enhancement.
Main “modern features” used are:
@barba/prefetch
also uses IntersectionObserver
Cross-browser support is as follows:
- without polyfills: modern browsers (Chrome, Firefox, Edge, Safari, Opera)
- with polyfills for abovementioned: + IE10
You can use polyfill.io:
1 | <script |
or implement your own solution (es6-promise and Core.js or es6-shim, …).