Documentation

Page Prefetching

hy-push-state starts a HTTP request as soon as the user “hints” that he/she is about to open a new page by hovering, focusing, or touching (touchstart-ing) a link. If the guess is correct, the request has a 100ms or more head-start, further increasing the perceived speed of your site in addition to the already fast webapp-style page replacing.

Unlike other implementations of this feature, the current prefetch request will be canceled if the user hints at a different link, ensuring that there will be no more than one prefetch request in flight at a time. This avoids clogging up the network with requests that are going to be discarded upon arrival, which is essential when on slow 3G connections.

For example, hovering links in the sidebar on qwtel.com will produce a timeline like the one below:

hy-push-state allows building advanced page transition animations, like the ones used in Hydejack and state-of-the-art web apps. These can be promise-based instead of time-based to account for smaller delays caused by other code, GC interruptions, or slower devices in general

The code for a simple fade-out animation using the Web Animations API may look like:

pushStateEl.addEventListener('hy-push-state-start', ({ detail }) =>
detail.waitUntil(new Promise(res =>
document
.getElementById('my-content')
.animate([{ opacity: 1 }, { opacity: 0 }], { duration: 250 })
))
);


Time-based animations are possible as well and are configured with the duration option.

Gold Standard

This component follows the Web Components Gold Standard.

Source

The source code is written in a literal programming style, and should be reasonably approachable. However, some knowledge of RxJS is required.

The core functionality is implemented in mixin / index.js, which is used to create the framework-specific versions of the component.

Size

The size of the minified bundle is around 90kb, or ~20kb gzipped. The majority of it comes from RxJS. When already using RxJS in your project, or using more than one component of the Hydejack component family, consider using a frontend bundler.

Size File
95K dist/jquery/index.js
20K dist/jquery/index.js.gz
91K dist/mixin/index.js
19K dist/mixin/index.js.gz
92K dist/vanilla/index.js
19K dist/vanilla/index.js.gz
97K dist/webcomponent/html-import.js
20K dist/webcomponent/html-import.js.gz
97K dist/webcomponent/index.js
20K dist/webcomponent/index.js.gz
97K dist/webcomponent/module.js
20K dist/webcomponent/module.js.gz