Last active
March 23, 2016 20:38
-
-
Save atrakeur/9faa8356261c8c8f3bf0 to your computer and use it in GitHub Desktop.
Sample code on how a website can hide page loading to look a lot faster. Full blog post here: https://www.atrakeur.com/blog/art34-rendez_votre_site_plus_rapide_simplement_avec_pjax_et_nprogress
This file contains 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
//Configure pjax | |
new Pjax({ | |
elements: "a", //Quel type d'élément binder pjax (les liens) | |
selectors: ["title", ".mainContent", ".top-nav-menu"], //Quels parties du html doivent changer entre les pages | |
}); | |
//Configure NProgress | |
NProgress.configure({ | |
minimum: 0.1, | |
rickleRate: 0.2, | |
trickleSpeed: 250 | |
}); | |
//Start loading on pjax request | |
$(document).on('pjax:send', function() { | |
NProgress.start(); | |
}) | |
//Stop loading when pjax is done (success or error) | |
$(document).on('pjax:complete', function() { | |
NProgress.done(); | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment