Git Product home page Git Product logo

pace's Introduction

PACE

Latest Release jsDelivr hits (npm) Stars Forks License

An automatic web page progress bar.

Include pace.js and the theme css of your choice on your page (as early as possible), and you're done!

Pace will automatically monitor your ajax requests, event loop lag, document ready state, and elements on your page to decide the progress. On ajax navigation it will begin again!

If you use AMD or Browserify, require pace.js and call pace.start() as early in the loading process as possible.

Example

<head>
  <script src="https://cdn.jsdelivr.net/npm/pace-js@latest/pace.min.js"></script>
  <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/pace-js@latest/pace-theme-default.min.css">
</head>

Configuration

Pace is fully automatic, no configuration is necessary to get started.

If you would like to make some tweaks, here's how:

You can set window.paceOptions before bringing in the file:

paceOptions = {
  // Disable the 'elements' source
  elements: false,

  // Only show the progress on regular and ajax-y page navigation,
  // not every request
  restartOnRequestAfter: false
}

You can also put options on the script tag:

<script data-pace-options='{ "ajax": false }' src="https://cdn.jsdelivr.net/npm/pace-js@latest/pace.min.js"></script>

If you're using AMD or Browserify, you can pass your options to start:

define(['pace'], function(pace){
  pace.start({
    document: false
  });
});

Themes

Pace includes a bunch of themes to get you started. Just include the appropriate css file. Send us a PR with any interesting themes you create.

If you have minor styling changes and don't want to extend theme css, you can add custom class names to the progress bar using the "className" option:

paceOptions = {
  className: 'my-custom-class'
}

Collectors

Collectors are the bits of code which gather progress information. Pace includes four default collectors:

  • Ajax

    Monitors all ajax requests on the page

  • Elements

    Checks for the existence of specific elements on the page

  • Document

    Checks the document readyState

  • Event Lag

    Checks for event loop lag signaling that javascript is being executed

They can each be configured or disabled through configuration options of the same name.

paceOptions = {
  ajax: false, // disabled
  document: false, // disabled
  eventLag: false, // disabled
  elements: {
    selectors: ['.my-page']
  }
};

Add your own classes to paceOptions.extraSources to add more sources. Each source should either have a .progress property, or a .elements property which is a list of objects with .progress properties. Pace will automatically handle all scaling to make the progress changes look smooth to the user.

Elements

Elements being rendered to the screen is one way for us to decide that the page has been rendered. If you would like to use that source of information (not required at all), specify one or more selectors. You can comma separate the selectors to properly handle error states, where the progress bar should disappear, but the element we are looking for may never appear:

paceOptions = {
  elements: {
    selectors: ['.timeline, .timeline-error', '.user-profile, .profile-error']
  }
}

Pace will consider the elements test successful when each selector matches something. For this example, when either .timeline or .timeline-error exist, and either .user-profile or .profile-error exist.

Restart Rules

Most users want the progress bar to automatically restart when a pushState event occurs (generally means ajax navigation is occuring). You can disable this:

paceOptions = {
  restartOnPushState: false
}

You can also have pace restart on every ajax request which lasts longer than x ms. You'll want to disable this if you make ajax requests the user doesn't need to know about, like precaching:

paceOptions = {
  restartOnRequestAfter: false
}

You can always trigger a restart manually by calling Pace.restart()

See the source for a full list of options.

API

Pace exposes the following methods:

  • Pace.start: Show the progress bar and start updating. Called automatically if you don't use AMD or CommonJS.

  • Pace.restart: Show the progress bar if it's hidden and start reporting the progress from scratch. Called automatically whenever pushState or replaceState is called by default.

  • Pace.stop: Hide the progress bar and stop updating it.

  • Pace.track: Explicitly track one or more requests, see Tracking below

  • Pace.ignore: Explicitly ignore one or more requests, see Tracking below

Events

Pace fires the following events:

  • start: When pace is initially started, or as a part of a restart
  • stop: When pace is manually stopped, or as a part of a restart
  • restart: When pace is restarted (manually, or by a new AJAX request)
  • done: When pace is finished
  • hide: When the pace is hidden (can be later than done, based on ghostTime and minTime)

You can bind onto events using the on, off and once methods:

  • Pace.on(event, handler, [context]): Call handler (optionally with context) when event is triggered
  • Pace.off(event, [handler]): Unbind the provided event and handler combination.
  • Pace.once(event, handler, [context]): Bind handler to the next (and only the next) incidence of event

Tracking

By default, Pace will show any ajax requests which begin as a part of a normal or ajax-y page load, or which last longer than 500ms.

You can disable all ajax tracking by setting ajax to false:

Pace.options = {
  ajax: false
}

You can disable ajax tracking except on page navigation by setting restartOnRequestAfter to false:

Pace.options = {
  restartOnRequestAfter: false
}

You can manually disable tracking for a specific request or requests by triggering them within a Pace.ignore callback:

Pace.ignore(function() {
  $.ajax(...)
});

You can force the progress bar to be shown for a specific request by triggering them within a Pace.track callback:

Pace.track(function() {
  $.ajax(...)
});

You can also ignore URLs based on a pattern:

Pace.options = {
  ajax: {
    ignoreURLs: ['some-substring', /some-regexp/]
  }
}

Dependencies

None!

Support

Pace is designed to support IE8+ (standards mode), FF 3.5+, Chrome, Safari 4+, Opera 10.5+, and all modern mobile browsers. If you run into a compatibility issue, or can make a case for supporting something else, please create an issue.

Size

pace.js is 4kb minified and gzipped. The themes vary between 0.5 and 4kb.

Issues

We have obviously not tested this on every website. If you run into an issue, or find a way the automatic detection could be better, please create an Issue. If you can include a test case, that's even better.

Credits

HubSpot

CodeByZach

Javascript by Zack Bloom CSS by Adam Schwartz

Themes inspired by Mary Lou

Project inspired by nprogress

pace's People

Contributors

adamschwartz avatar alessandro-diez avatar cha147 avatar clayzermk1 avatar codebyzach avatar dyatko avatar endel avatar frandias avatar friss avatar graingert avatar hugomrdias avatar jeremygeros avatar jeremywrowe avatar kaleworsley avatar kennyglenn avatar luukbosma avatar mascah avatar muraker avatar mxgr7 avatar mylesduncanking avatar rizzomichaelg avatar rogeriopvl avatar thorikawa avatar timgates42 avatar traviscross avatar trevorburnham avatar vectart avatar vinceshere avatar xinan avatar zackbloom avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

pace's Issues

what's the license?

What's the license of pace.js ? Please add a LICENSE file in github repo. So that users can know whether they can use it in commercial cases, etc. :-)

Start Pace when iFrame is opening

Hey there. I'm building an website where there are some examples of a chart library, and i've got a select object that will specify the chart type to show, and will load an iframe with it's type samples. I wish I could start Pace as soon as I change the chart type. Is there any way to do that?

Thanks in advance, and congrats for the great job done here!

Pace broken in Firefox

Since v0.4.8, pace is not loading in Firefox (23.0.1 on OS X). I have the following issue:
TypeError: Value does not implement interface XMLHttpRequest. (at line 231)

Including with Turbolinks breaks Turbolinks page refresh

Without too much diagnoses, my current app works with Turbolinks, and each page only loads the body component as it should.

Adding Pace to the site causes each navigation to fail and force a full page refresh:

Uncaught Error pace.js?body=1:3
b pace.js?body=1:3
a.getElement pace.js?body=1:3
a.destroy pace.js?body=1:3
Pace.stop pace.js?body=1:3
Pace.restart pace.js?body=1:3
x pace.js?body=1:3
window.history.replaceState.window.history.replaceState pace.js?body=1:3
rememberCurrentUrl turbolinks.js?body=1:167
initializeTurbolinks turbolinks.js?body=1:381
(anonymous function) turbolinks.js?body=1:410
(anonymous function) turbolinks.js?body=1:422

Callback events?!

There is some trick to trigger some function on callback?
Like trigger some show content functionn after pacejs completes the loading progress!

Tks in advance!

New Theme Request + How To Fix

Hello!

I would like to see a flipping circle progress theme in the future like this one: iphonetemplates.com

Also, please point me to how can I make a page load progress fade out after the page is ready to go.

Sort of 1) one page for load progress with counter.. page loaded -- fade out 2) main page

Best Regards!

If pace js included before turbolinks js the I get an error in the console

I get this error:
Uncaught TypeError: Cannot read property 'firstChild' of null

On line 136:
if (targetElement.firstChild != null) {

By default targetElement is supposed to be the 'body' tag. However, the querySelector lookup for 'body' comes back as null only if the pace.js file is included before the rails turbolinks.js. If I switch the order then it works fine.

This isn't too big of a deal for me but it did take a bit of time to figure out what was the cause of the error.

AngularJS support

Hi,

I try to use pace in one AngularJS application, it seems not work at all.
It will freeze the browser or cause some Javascript error output to the console.

Progress not repainting in IE and Firefox

In IE and Firefox (tested in IE11 and FF25) the trickle style changes don't get repainted properly. A repaint doesn't seem to occur at all during the main animation, only in the final jump to 100% when done. Chrome performs the repaint fine.

I had some success forcing IE to repaint by cycling the progress element through 'display: none', but can't work out a solution that works in Firefox.

when close ajax error

window.paceOptions = {
eventLag: false,
//document: false,
//elements: false,
ajax: false
};

qq20130929140058

when set the value of ajax is false appear error

download

is it possible to show the progress bar, when i click a link to download a file until the download has finished?

Better control over what requests show Pace

As it stands, Pace is designed to only show up on what would be called a 'page load'. Either the initial load, or ajax-y navigation.

It would be good if there was a way to make it appear when an arbitrary request is made.

Minify CSS?

Would be really helpful (although it's small) to have the CSS minified.

pace breaking on ajax: true or ajax false

here is my config:

  paceOptions = {
    target:'.pace-loading',
    ajax: false,
    document: true,
    eventLag: true,
    elements: {
      selectors: ['img']
    }
  };

causes all ajax request to not fire.

  paceOptions = {
    target:'.pace-loading',
    ajax: true,
    document: true,
    eventLag: true,
    elements: {
      selectors: ['img']
    }
  };

also causes all ajax request to not fire.

When using livereload it causes an issue.

This is the error:

WebSocket connection to 'ws://localhost:35729/livereload' failed: Error during WebSocket handshake: Sec-WebSocket-Protocol mismatch pace.js:285

Is there a way to exclude certain url patterns?

how to stop pace on window load

how to stop pace on window load? and how do i start it on click?

$(function(){
    Pace.stop();
    Pace.options = {
  ajax: false, // disabled
  document: false, // disabled
  eventLag: false, // disabled
  elements: {
    selectors: ['body'],
  },
   restartOnRequestAfter: false,
   restartOnPushState: false
};
});



jQuery('.thumb').click(function(e){
    Pace.start();   
});

Remove delay

Hello. I am using flash effect on my site, but when browser is loaded and refresh button appeared, PACE is still showing that it is loading. No ajax requests, dust a delay.
How to remove it?
Reproduce: http://ru.artactivator.com/

create a stop forever option

i'm using a spa app where most of the long-loading stuff happens once at the initial load of the app. (see gmail.com for an example). like gmail, it shows a loading graphic during that initial load but never does again. this is what i'd like to happen.

i've modified the code locally, in a very quick and very dirty way, to have a parameter on the stop() function. it just then sets a global variable to true.

so for example,

var paceStopForever = false;

Pace.stop = function (forever) {
if (forever) { paceStopForever = true; }
...
};

then in the start() and go() routines i just check for that variable:

Pace.go = function () {
if (paceStopForever) return null;
...
};

Pace.start = function () {
if (paceStopForever) return null;
...
}

it's a terrible way to do it, i know, but it works.

would be great to include it in the actual code.

thanks for a great product!

  • eric

jQuery.ajax is not detected automaticlly

At the documentation:

Pace will automatically monitor your ajax requests, event loop lag,
document ready state, and elements on your page to decide the progress.
On ajax navigation it will begin again!

It should display the progress on every Ajax request, or not? If yes, does Pace need some extra configuration to work correctly with $.ajax?

After the page is loaded and the Pace progress is hidden, no matter how many ajax requests the page do, the progress only appears again when i manually call the Pace.restart() method before an ajax request, and even if I put a sleep(10) in the PHP, to delay it, the progress will appear and hide immediately

Sorry for my poor english.

Pace breaking Socket.io in Chrome 30

Pace is breaking my webpage after upgrading to Chrome 30.

The error message is:
WebSocket connection to 'ws://crmv3.emeieme.com/socket.io/1/websocket/U30BuBH6JOHipg3Mx0Wp' failed: Error during WebSocket handshake: Sec-WebSocket-Protocol mismatch

If I disable pace, everything starts working again.
My page is http://crmv3.emeieme.com (inside the Chat tab)

I'm using 0.4.13

Doesn't work at all in IE10

I hate to be that guy... but it would be cool if this worked on IE 10 - true cross browser solution for loading.

The load from top works but not so much the rest

howto: ajax only?

hi,

first: nice lib and great work. Second: sorry i could not figure out how to only show the progress bar on ajax requests? i dont want to show it on every page load.

thanx

Cannot call method 'on' of undefined

Not working with backbone,

Error on line:

646: return Backbone.history.on('route', function(router, name) {

BTW what is the compatibility version of backbone?

eventLag causes long delay

When eventLag is true takes approx 1.5 - 3 seconds to complete the animation. When I set it false almost immediate. What could be causing this?

how does speed work

how does one speed up the process of the loading bar? or is it based entirely on the page load?

Doesn't work with Backbone

Hello,

it seems that the plugin doesn't detect Backbone's ajax requests, as I'm trying to use it on a Backbone app and it doesn't appear (apart from the dom first load)

Any advice about how to fix it?

Thanks

IE 8, 7 compatibility

In IE 7 I get the error:

SCRIPT5009: 'JSON' is undefined
color.js, line 24 character 12960
SCRIPT438: Object doesn't support property or method 'querySelector'
pace.js, line 115 character 5

Pace never stops with PubNub

First of all Pace is awesome, but I can't make it work in my web app because it is tracking all PubNub requests, so the bar always stay visible even with new Ajax requests.
I am using Ember.js and PubNub generally make a lot of requests for listen channels and other actions.
Some help over here! Thanks in advance.

Installation

can you please tell us exactly how to embed this on a page?

Can't get AJAX request to show progress

Thanks for publishing such a cool idea. I'd really love to get this working, but I'm having trouble trying to get a simple demo going on JSBIN at this address: http://jsbin.com/obUHiX/6/

It shows the progress when the page initially loads just fine, but doesn't show when the AJAX request is initiated. This request calls a simple service I cooked up for testing, which simply returns the current date and time after a random delay:

https://github.com/toddwprice/ajaxfaker/blob/master/app.js

I've tested in Firefox 24, Chrome 29, and Safari 6, all with the same results. Any thoughts?

Pace Minimalist does not go all the way to right edge. Intentional?

I'm noticing that most of the time Pace decided to start the loader on the top of the page, gets maybe 30% of the way there, then disappears. Even if it only gets to a progress of 30 and completes, shouldn't it animate to width 100% then fade out? (like Youtube's, nProgress and Skylo's implementation).

Is this a setting of the theme, or is this part of pace?

Syntax error

Just by adding pace.js to the head section you get a nice error:
image

Using IE9. All other plugins working Ok. Jquery, Bootstrap, etc...

Websocket support

Go to http://www.websocket.org/echo.html , open network inspector (in Chrome/Safari/Opera) and then hit "Connect".
You'll see that a pending "Switching boards 101" will be pending forever. This will cause pace to not hide in a single-page webpage with websockets.

Big counter

Hi! I try few times this progress bar and I can't get the demo of bi counter working.
With the other themes (css files) it works, while with pace-theme-big-counter.css not, nothing is displayed.

Functionality to disable pace completely

Currently there is an issue with pace.js, require.js and legacy browsers that are not supported.

The problem is that pace is activated automatically after its loaded. That means that if we are using require.js, then there is no "clean" way to turn pace off (or to exclude it from loading) for legacy browsers that are not supported (ie7 for example). Especially so when one is replacing requirejs with almond during the compile step.

To avoid issues like that, then It would be nice to have an option to turn off pace completely.

How to specify lcation of loading indicator

Hi,

i dont know if i miss something here, but can I specify where the loading indicator should appear? For example if I open a bootstrap-modal the loading, as i think, should appear inside of the modal. Sometimes you also want the loading to apear just right next to the button or in the button itself...

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.