predictive-prefetch

0.1.0 • Public • Published

Predictive Prefetch · GitHub license npm version PRs Welcome

100% client side, out of the box predictive prefetch solution for webpack and modern SPAs, based on alz-predictor.

  • Webpack: Learn, predict and prefetch JavaScript modules or chunks and other supported assets in runtime.

  • SPA: Predict and prefetch user's next Route or URL, e.g: from React Router.

  • Unlike Guess.js, Predictive Prefetch doesn't require any third party data analytics sources.

Why?

  • Speed up user future navigation.
  • 100% frontend AI solution.
  • Privacy, data is stored and kept locally.

FAQ

How it works?

  • Monitor any mutation change in the document object looking for JavaScript tags and other supported assets.

  • Intercept history pushState looking for changes in routes.

  • Train ALZ Predictor and predict next asset or route.

  • Add link tag with prefetch rel for the previous prediction.

Installation

# Yarn
yarn add predictive-prefetch

# NPM
npm install --save predictive-prefetch

Usage

import PredictivePrefetch from 'predictive-prefetch'

PredictivePrefetch();

Configuration

Predictive Prefetch includes options for:

  • assets: disable script and/or other resources monitoring.
  • urls: disable url intercepting.
  • predictor: calibrate prefetch minimum probability.

Default options

import PredictivePrefetch from 'predictive-prefetch'

const options = {
    assets: {
        scriptsDisabled: false, 
        resourcesDisabled: true,
        };
    urls: {
        disabled: false,
    };
    predictos: {
        minProbability: 0.7,
    };
};

PredictivePrefetch(options);

License

Predictive Prefetch is MIT licensed.

Package Sidebar

Install

npm i predictive-prefetch

Weekly Downloads

1

Version

0.1.0

License

MIT

Unpacked Size

24 kB

Total Files

4

Last publish

Collaborators

  • mudafar