• Stars
    star
    147
  • Rank 251,347 (Top 5 %)
  • Language
    JavaScript
  • Created over 7 years ago
  • Updated over 6 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

๐Ÿ”ฎ Predicts when a link is about to be clicked

futurelink

Calculates the deceleration of the cursor to predict when a link is about to be clicked.

Install

$ npm install --save futurelink

Usage

var futurelink = require('futurelink');

futurelink({
  links: document.querySelectorAll('a'),
  future: function (link) {
    // `link` is probably going to be clicked soon
    // Preload some images, if you can!
  },
  
  // These also exist, but aren't usually needed:
  hover: function (link) {},
  click: function (link) {}
})

Pass it an array or NodeList of elements, and when the cursor is approaching one of those elements, the future callback will be fired with the element in question as an argument. future will only be called once per element.

The links are read directly from the options object, so if you want to update the links being watched (say, because you want to watch some elements newly added to the DOM), you can do this:

var options = {
  links: document.querySelectorAll('a'),
  future: function (link) {}
};

futurelink(options);

router.afterEach(function () {
  options.links = document.querySelectorAll('a');
});

Disabling for sections of the page / individual links

futurelink won't look at links that have a no-futurelink class on them or one of their parent elements. It also only looks at internal links.

<div class="no-futurelink">
  <a href="/foo-bar">Futurelink won't tell you about this link</a>
</div>

<a href="/bar-foo" class="no-futurelink">It won't tell you about this one either</a>

Removing futurelink from the page

If you want to completely remove futurelink, it returns a teardown function that you can call:

var teardown = futurelink(options);

// Laterโ€ฆ

teardown();

Now the event listeners will be removed and futurelink won't tell you when links are about to be clicked anymore.

How effective is it

On samknows.com, it speeds up non-initial page loads by an average of 870ms.

How does it work?

You can see an article about that on the SamKnows Medium.

Usage with frameworks

License

Released under the MIT license.

More Repositories

1

transform-when

๐ŸŽž๏ธ A library for handing animations combining page position and time
JavaScript
153
star
2

tryregex

๐Ÿ“– An interactive regex tutorial
HTML
103
star
3

vue-test

๐Ÿ DEPRECATED: Component testing for Vue.js
JavaScript
90
star
4

regex-tuesday

๐Ÿ“† The repo for the regex tuesday challenges
JavaScript
87
star
5

gulp-w3cjs

๐Ÿšฆ w3cjs wrapper for gulp to validate your HTML
JavaScript
56
star
6

rev-del

๐Ÿ’‡ Delete old fingerprinted files
JavaScript
35
star
7

vue-futurelink

Preload links about to be clicked with futurelink.
Vue
34
star
8

path.js

A library for morphing between SVG paths
JavaScript
20
star
9

animation-talk-demo

Vue
19
star
10

if_changed

๐Ÿ“ฅ Run commands on git pull
Shell
17
star
11

sketchbook

๐ŸŽจ
TypeScript
15
star
12

when-scroll

๐Ÿ“œ A library for firing callbacks when the user scrolls
JavaScript
14
star
13

find-node-modules

โฌ†๏ธ Return an array of all parent node_modules directories
JavaScript
13
star
14

timerizerJS

โฐ A library for working with relative times in JS.
JavaScript
11
star
15

covid-visualisations

Companion repository for my "Building an animated COVID-19 tracker using Vue.js" article.
Vue
10
star
16

learning-from-jquery

๐Ÿ“˜ The code repository for Learning from jQuery
JavaScript
10
star
17

dotfiles

โ„น๏ธ My dotfiles
Perl
8
star
18

phpBB-Mobile

๐Ÿ˜ด An old, unmaintained modification for phpBB to make it mobile friendly
PHP
8
star
19

macr.ae

๐Ÿ˜„ My website!
Vue
7
star
20

whtevr

๐Ÿ’ The lazy loading library that just doesn't care.
JavaScript
6
star
21

phpbb-ideas_old

An idea center for phpBB (based on WordPress idea center).
PHP
6
star
22

Hex

An IRC bot for the x10hosting IRC, written in Node.js
JavaScript
6
star
23

PHPCheck

A testing library for PHP loosely based on Haskell's QuickCheck library.
PHP
6
star
24

gulp-contains

โœ‹ Throws an error or calls a callback if a given string is found in a file.
JavaScript
5
star
25

phpbbmobile-style

Style to be used with phpBB Mobile
JavaScript
5
star
26

obj-to-attrs

โžก๏ธ Turns a JavaScript object into a string containing HTML attributes.
JavaScript
4
star
27

sudoku-creator

An algorithm to create a solvable Sudoku puzzle.
JavaScript
4
star
28

lynx.io

The source for the new lynx.io website
JavaScript
4
star
29

MatrixJS

A matrix library for JavaScript and Node.js.
JavaScript
3
star
30

perf-test

Vue
3
star
31

baconjs

A dead JavaScript framework I wrote ages ago.
JavaScript
3
star
32

url-shortener

A simple URL shortener library
PHP
3
star
33

lynx-framework

A framework built by the admin of lynxphp, Callum Macrae
PHP
3
star
34

afk

๐Ÿ’ค JavaScript library to handle user going inactive
JavaScript
3
star
35

touch-screen

๐Ÿ“ฑ Detects touch screens, in theory.
JavaScript
3
star
36

after-delay

โŒ› Basically setTimeout on steroids
JavaScript
3
star
37

js-irc

An IRC client written in Node.js and JavaScript
JavaScript
3
star
38

climb-trump-tower

Climb Trump Tower
JavaScript
3
star
39

phpbb-vagrant

phpBBโ€ฆ on Vagrant
2
star
40

charity-massage

๐Ÿ’† A massage scheduling app to raising money for charity.
JavaScript
2
star
41

vinyl-fs-fake

๐Ÿ˜ Extends vinyl-fs to be testable
JavaScript
2
star
42

tresjs-block-game

A Minecraft-like environment powered by TresJS
TypeScript
2
star
43

find-node-modules-down

โฌ‡๏ธ Find child node_modules directories
JavaScript
2
star
44

art

๐ŸŽจ experiments!
JavaScript
2
star
45

c-algos

A collection of algos I have implemented in C.
C
2
star
46

codepen-game

๐ŸŽฎ A game you can play in codepen!
TypeScript
2
star
47

plist

Parses iTunes library and tells the user how long they have listened to iTunes for
PHP
2
star
48

cypress-select-value-issue

Vue
2
star
49

baconjs-django-template

A Django template language parser for JavaScript
JavaScript
2
star
50

socialSharesBookmarklet

A bookmarklet to show you how many times something has been shared.
JavaScript
2
star
51

news-script

A simple news script written in PHP.
JavaScript
2
star
52

toggle

๐Ÿ”„ A tiny toggle library
JavaScript
2
star
53

lang

๐ŸŒŽ An tiny language library
JavaScript
2
star
54

lastfmbot

An IRC bot for last.fm .np commands
JavaScript
2
star
55

js-bot

An IRC bot that executes any JavaScript that is sent to it and outputs the result back into the channel.
JavaScript
2
star
56

webpack-inline-loader-error

See stackoverflow for detailed description of problem!
JavaScript
2
star
57

intentiothemes.com

The source code for Intentio website
JavaScript
2
star
58

andro

A dark theme for an evil amount of editors.
2
star
59

vue-photo-album

TypeScript
2
star
60

js-labs

A set of simple experimental apps written in JavaScript.
JavaScript
2
star
61

nums

1๏ธโƒฃ 2๏ธโƒฃ 3๏ธโƒฃ nums(3, 6) => [3, 4, 5, 6]
JavaScript
2
star
62

colour.js

A colour manipulation library for JavaScript
JavaScript
2
star
63

radial-elevation

JavaScript
1
star
64

css-test

An experiment to see how far CSS3 can be pushed
PHP
1
star
65

jacob.reviews

๐Ÿ˜ˆ Reviews of jacob
JavaScript
1
star
66

960

Very simple 960 grid system library
1
star
67

gulp-cssnano

Minify CSS with cssnano.
JavaScript
1
star
68

sketchbook-2

TypeScript
1
star
69

jscheck_prettify

This project takes JSCheck and handles reports, adding a nice interface on the reports.
JavaScript
1
star
70

notunhelpful

An IRC bot to op people and stuff
JavaScript
1
star
71

Akismet

An Akismet library written in object orientated PHP
PHP
1
star
72

parsesearch

JavaScript
1
star
73

typescript-bug

JavaScript
1
star
74

callum.reviews

๐Ÿ˜ฐ Reviews of Callum.
JavaScript
1
star
75

about-me

๐Ÿ˜Ž โ˜บ๏ธ
JavaScript
1
star
76

Graph

A simple graphing library for JS
JavaScript
1
star
77

numbers.py

Converts numbers in word form (such as "two hundred and thirty-seven") to proper integers (237).
Python
1
star
78

where-was-callum

๐Ÿ”Ž๐ŸŒ a lil experiment
JavaScript
1
star
79

Zirck

JavaScript
1
star
80

webrtc-net

๐Ÿ•ธ๏ธ WIP WIP. WebRTC powered network using a gossip algorithm to propagate messages.
JavaScript
1
star
81

JSColor

๐Ÿ”ด ๐Ÿ”ต JSColor + Bower
JavaScript
1
star
82

Count-thing

My first C project: Attempts to prove that the fact that there are 500,000,000 "1"s in the first 500,000,000 positive integers isn't remarkable.
C
1
star