Skip to content

Instantly share code, notes, and snippets.

@atrakeur
Last active March 23, 2016 20:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save atrakeur/9faa8356261c8c8f3bf0 to your computer and use it in GitHub Desktop.
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
//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