How it works
barba.js uses PJAX (aka push state ajax) to enhance the user's experience.
This technique consist of preventing the normal link behavior, changing the browser url manually, and manually injecting the new content in the page. In this way there will be no browser "hard refresh".
Here is a walkthrough of what happens when the user clicks a link:
- Check if the link is valid and eligible for PJAX. If yes, prevent the normal browser behavior.
- Change the URL using the push state API.
- Start fetching the new page via a XMLHttpRequest.
- Create a new transition instance.
- As soon the new page is loaded, barba.js parses the new HTML (taking
.barba-container) and puts the new content on the DOM inside
- The transition instance will take care of hiding the old container and showing the new one.
- As soon the transition is finished, the old container is removed from the DOM.
In order to have a better understanding on how Barba.js works I suggest you to read this article I wrote for Smashing Magazine.
Using this technique will bring numerous benefits: