+0
日增长
15,582
stars
1,830
forks
358
watchers
118
prs
455
issues
21
releases
README
PACE
====
An automatic web page progress bar.
Demo
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
-------
html
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:
javascript
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 (the value must be valid JSON):
html
Pace reads its options once, when pace.js loads, so set them before including it.
Assigning Pace.options afterwards has no effect.
If you load pace with a bundler or module loader (AMD or CommonJS), it doesn't start on its own:
set window.paceOptions before pace loads, then call Pace.start(). import statements run
before the rest of a file, so put the options in their own file and import it first:
javascript
// pace-options.js
window.paceOptions = {
document: false
};
javascript
// your entry file
import './pace-options.js';
import Pace from 'pace-js';
Pace.start();
With RequireJS, set window.paceOptions in a before calling require(['pace'], ...).
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:
javascript
paceOptions = {
className: 'my-custom-class'
}
Collectors
----------
Collectors are the bits of code which gather progress information. Pace includes four default collectors:
- Ajax
Monitors ajax requests (XMLHttpRequest and WebSocket) on the page. Only GET requests are tracked by default, see Tracking below
- 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.
javascript
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 aTop issues
#531loading stuck on 99%15 comments · 2021-11-18#261Breaks class properties of XmlHTTPRequest13 comments · 2015-10-13#129allow manually starting stopping13 comments · 2014-06-09#510Latest version in Firefox9 comments · 2020-12-14#515Class pace-done added to body multiple times8 comments · 2021-02-25#333Add a monitor for `window.fetch`8 comments · 2016-07-06#115show when submitting a form8 comments · 2014-04-13#272Pace compatibility with ng-file-upload5 comments · 2015-11-16
Latest release
Version 1.3.1 v1.3.1 2026-11-05Fixes - Pace no longer stays running forever when eventLag: false is passed to Pace.start(), for example after loading pace with a bundler. The event-lag check now keeps the settings it was created with. Documentation - The README's bundler example now works: set window.paceOptions in a module imported before pace (or, with RequireJS, in a script before require()), then call Pace.start(). - The progress event is now listed in the README's Events section.