Visibility.js is a wrapper for the Page Visibility API. It hides vendor prefixes and adds high-level functions.
Page Visibility API allows you to determine whether your web page is either visible to a user or hidden in the background tab or prerendering. It allows you to use the page visibility state in JavaScript logic and improve browser performance by disabling unnecessary timers and AJAX requests, or improve user interface experience (for example, by stopping video playback or slideshow when the user switches to another browser tab).
Moreover, you can detect if the browser is just prerendering the page while the user has still not opened the link, and don’t count this as a visit in your analytics module, or do not run heavy calculations or other actions which will disable the prerendering.
Page Visibility API is natively supported by all browsers. For old browsers, you can use lib/visibility.fallback.js
with focus/blur hack (note that this hack has an issue: when the browser has just lost focus, but is still visible for the user, its state will change to [hidden]).