Là một dự án mã nguồn mở, CodeByZach/pace đã đạt 15.6k sao trên GitHub, ngôn ngữ JavaScript. Automatically add a progress bar to your site.
Tóm tắt dựng từ metadata GitHub của chính dự án — chưa có bài review TopGit. Trang sẽ tự động cập nhật khi bài review đầy đủ được xuất bản.
VÌ SAO CHƯA CÓ REVIEW
TopGit viết bài đầy đủ cho repo có nhiều sao nhất và được yêu cầu nhiều nhất. Trang này là snapshot trong thời gian chờ — xem README gốc ở tab READ ME.
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.
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 (the value must be valid JSON):
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:
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:
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
}
This also covers links whose scripts change the URL with history.pushState or replaceState
(some tab, accordion and scrollspy plugins do).
Pace also restarts for any tracked ajax request that is still running after restartOnRequestAfter
milliseconds (500 by default). Set a different number, or false to turn this off 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)
progress: On every frame while the bar is running, with the current progress (0–100)
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.
Only GET requests are tracked by default. To also show the bar for other methods, such as form saves sent with POST:
A string matches any ajax request URL that contains it (case-sensitive); a regular expression is tested against
the URL. These patterns only apply to ajax requests, not to links, images or other resources on the page.
WebSocket connections are tracked too. To stop that, set trackWebSockets: false inside ajax.
A few things Pace can't track:
Requests sent with async: false block the page until they finish, so the bar can't animate during them.
Downloads started by a plain link aren't ajax requests.
Avoid calling Pace.restart() for every request, for example from jQuery's ajaxStart. It restarts the bar even for
ignored requests, and parallel requests restart it several times. To show the bar for POST requests, add POST to
trackMethods as shown above.
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.
CodeByZach/pace có 15.6k sao GitHub — tải lại trang để xem số mới nhất, hoặc xem trực tiếp github.com/CodeByZach/pace. TopGit phản chiếu số sao của GitHub nhưng không cam kết đến từng phút.
CodeByZach/pace có những chủ đề gì?
GitHub topics của CodeByZach/pace: "loading-animation", "loading-bar", "loading-indicator", "pace", "pace-js", "progress-bar". TopGit xếp repo vào nhóm mã nguồn mở.
CodeByZach/pace còn đang phát triển không?
Commit gần nhất trên CodeByZach/pace là 12 ngày trước (theo timestamp GitHub). Repo có 1.8k fork — một chỉ báo về mức độ quan tâm của cộng đồng.
CodeByZach/pace là gì?
CodeByZach/pace (CodeByZach/pace) là dự án JavaScript trên GitHub. Theo mô tả gốc: Automatically add a progress bar to your site.
CodeByZach/pace viết bằng ngôn ngữ gì?
CodeByZach/pace chủ yếu viết bằng JavaScript. Trường "language" của GitHub dựa trên phần lớn byte ở nhánh mặc định.
Đọc đầy đủ README ở tab phía trên.
pace có đáng để bạn bỏ thời gian?
ChatGPT, Claude và Perplexity đều đọc được trang này. Hỏi thử xem họ nghĩ gì về pace.