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:

dev console screenshot Chrome developer console screenshot of prefetching requests.

Advanced Animations

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.transitionUntil(new Promise(res =>
    document
      .getElementById('my-content')
      .animate([{ opacity: 1 }, { opacity: 0 }], { duration: 250 })
      .addEventListener('finish', res)
  ))
);

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
84K dist/jquery/index.js
19K dist/jquery/index.js.gz
80K dist/mixin/index.js
18K dist/mixin/index.js.gz
81K dist/vanilla/index.js
18K dist/vanilla/index.js.gz
86K dist/webcomponent/html-import.js
19K dist/webcomponent/html-import.js.gz
86K dist/webcomponent/index.js
19K dist/webcomponent/index.js.gz
86K dist/webcomponent/module.js
19K dist/webcomponent/module.js.gz

© 2018 Florian Klampfer

Powered by Hydejack v8.1.0