All Projects → mgechev → Guess Next

mgechev / Guess Next

🔮 Demo application showing the integration of Guess.js with Next.js

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Guess Next

guess-js.github.io
The website of Guess.js
Stars: ✭ 16 (-96.97%)
Mutual labels:  web-performance, ml
Compression
Data compression in TensorFlow
Stars: ✭ 458 (-13.26%)
Mutual labels:  ml
Openrec
OpenRec is an open-source and modular library for neural network-inspired recommendation algorithms
Stars: ✭ 360 (-31.82%)
Mutual labels:  ml
Featran
A Scala feature transformation library for data science and machine learning
Stars: ✭ 420 (-20.45%)
Mutual labels:  ml
Mindsdb
Predictive AI layer for existing databases.
Stars: ✭ 4,199 (+695.27%)
Mutual labels:  ml
Metaflow
🚀 Build and manage real-life data science projects with ease!
Stars: ✭ 5,108 (+867.42%)
Mutual labels:  ml
Csinva.github.io
Slides, paper notes, class notes, blog posts, and research on ML 📉, statistics 📊, and AI 🤖.
Stars: ✭ 342 (-35.23%)
Mutual labels:  ml
Mozjpeg
Improved JPEG encoder.
Stars: ✭ 4,738 (+797.35%)
Mutual labels:  web-performance
Awesome Mlops
A curated list of references for MLOps
Stars: ✭ 7,119 (+1248.3%)
Mutual labels:  ml
Machinejs
[UNMAINTAINED] Automated machine learning- just give it a data file! Check out the production-ready version of this project at ClimbsRocks/auto_ml
Stars: ✭ 412 (-21.97%)
Mutual labels:  ml
Prerender.js
Fast webpages for all browsers.
Stars: ✭ 411 (-22.16%)
Mutual labels:  web-performance
Differentiable Plasticity
Implementations of the algorithms described in Differentiable plasticity: training plastic networks with gradient descent, a research paper from Uber AI Labs.
Stars: ✭ 371 (-29.73%)
Mutual labels:  ml
Myvision
Computer vision based ML training data generation tool 🚀
Stars: ✭ 453 (-14.2%)
Mutual labels:  ml
Cs229 ml
🍟 Stanford CS229: Machine Learning
Stars: ✭ 364 (-31.06%)
Mutual labels:  ml
Fastocloud
Self-hosted IPTV/NVR/CCTV/Video service (Community version)
Stars: ✭ 464 (-12.12%)
Mutual labels:  ml
Snips Nlu
Snips Python library to extract meaning from text
Stars: ✭ 3,583 (+578.6%)
Mutual labels:  ml
Kglib
Grakn Knowledge Graph Library (ML R&D)
Stars: ✭ 405 (-23.3%)
Mutual labels:  ml
Lexpredict Lexnlp
LexNLP by LexPredict
Stars: ✭ 439 (-16.86%)
Mutual labels:  ml
Tryenlight.github.io
💻 Learn to code by building projects (old site!)
Stars: ✭ 493 (-6.63%)
Mutual labels:  ml
Garie
Open source web performance
Stars: ✭ 484 (-8.33%)
Mutual labels:  web-performance

🔮 Guess.js + Next.js

Guess.js is a collection of libraries & tools for enabling data-driven user-experience on the web.

In this particular example, we combine Guess.js with Next.js to introduce predictive prefetching of JavaScript bundles. Based on user navigation patterns collected from Google Analytics or other source, Guess.js builds a machine-learning model to predict and prefetch JavaScript that will be required in each subsequent page.

Based on early benchmarks, this can improve the perceived page load performance with 20%.

For more information on Guess.js, take a look at the following links:

Usage

Here's how you can try the demo:

git clone [email protected]:mgechev/guess-next
cd guess-next && npm i
npm run build && npm start

Demo

Integration

Guess.js (0.1.5 and above) works with Next.js with only two points of integration. All you need to do is add the GuessPlugin to next.config.js and introduce a snippet for prefetching the pages which are likely to be visited next.

The following sections describe both points in details.

Webpack Config

All you need is to extend the webpack config of your Next.js application is to add the GuessPlugin to next.config.js file, located in the root of your project. If the file does not exist, create it and add the following content:

const { GuessPlugin } = require('guess-webpack');

module.exports = {
  webpack: function(config, { isServer }) {
    if (isServer) return config;
    config.plugins.push(
      new GuessPlugin({
        GA: 'XXXXXX'
      })
    );
    return config;
  }
};

We set the value of the webpack property of the object literal we set as value to module.exports. We set it to a function which alters the GuessPlugin to the config.plugins array. Notice that we check if Next.js has invoked webpack on the server and we return.

As a value of the GA property, we set a Google Analytics View ID. At build time, Guess.js will open a browser and try to get read-only access to extract a report and use it for the predictive analytics.

Note that Google Analytics is not the only provider you can use to provide the user navigation report that Guess.js uses. In this example application we provide the report from a JSON file.

Prefetch Pages

The final piece of the integration is performing the actual prefetching. In your layout component (see components/layout.js) add:

import { guess } from 'guess-webpack/api';

// ...

  if (typeof window !== 'undefined') {
    Object.keys(guess()).forEach(p => router.prefetch(p));
  }

// ...

Keep in mind that we check if window is "undefined". This is required because we don't want to run Guess.js on the server. When we invoke guess(), we'll return a set of routes where each route will have an associated probability for the user to visit it.

The routes that guess() returns depend on the Google Analytics report that it has extracted, together with the user's effective connection type.

License

MIT

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].