Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
<!DOCTYPE html>
<html lang="en">
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<script src="index.js"></script>
let model = new CPT();
// GET This data from Google Analytics
let data = [
['/previous-page1', '/current-page1', '/next-slow-page1'],
['/previous-page2', '/current-page2', '/next-slow-page2'],
['/previous-page3', '/current-page3', '/next-slow-page1'],
['/previous-page4', '/current-page1', '/next-slow-page2'],
['/previous-page2', '/current-page3', '/next-slow-page3'],
['/previous-page3', '/current-page2', '/next-slow-page4'],
['/previous-page4', '/current-page1', '/next-slow-page1'],
data // Training Data
// replace place holder values for commented lines to test with real data
let previous_page = '/previous-page2';//document.referrer.replace(/^[^:]+:\/\/[^/]+/, '').replace(/#.*/, '');
let current_page = '/current-page3';//document.location.pathname;
let target = [
[previous_page, current_page]
let predictions = model.predict(
target, // Test input
2, // The number of last elements that will be used
// to find similar sequences, (default: target.length)
1 // The number of predictions required.
//This part inserts the browser hint dynamically based on the next page predicted
document.write(`<link rel="prefetch" href="${predictions}">`)
Testing Prefetch

This comment has been minimized.

Copy link

@jrosell jrosell commented Feb 4, 2020

I've seen that index.js should be downloaded from @dsottimano gist here

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment