Last active
February 4, 2020 09:11
-
-
Save hamletbatista/ee1b529e20e712aef365fb4c3957cfc1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8"> | |
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
<meta http-equiv="X-UA-Compatible" content="ie=edge"> | |
<title>Document</title> | |
<script src="index.js"></script> | |
<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'], | |
]; | |
model.train( | |
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}">`) | |
console.log(predictions) | |
</script> | |
</head> | |
<body> | |
Testing Prefetch | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I've seen that index.js should be downloaded from @dsottimano gist here https://gist.github.com/dsottimano/9dc98838d4e584088e8abf50b2384410