ForesightJS
What if we could only prefetch data the user actually needs?
pnpm add js.foresight
What is ForesightJs?
ForesightJS is a free and open-source JavaScript library that predicts user intent by analyzing mouse movements and trajectories. It allows developers to prefetch data based on user intent instead of the classic on-click or on-hover.
Trajectory Prediction
Predict based on movement and volicity where the user's cursor is heading, allowing for early prefetching.
Element Hit Slop
Add custom hit areas around elements to trigger actions before the user actually hovers over the element itself.
Efficient Prefetching
Save bandwidth by only prefetching what users will actually need, instead of prefetching everything in the viewport like traditional approaches.
Try It Yourself
Note: The interactive demos on this page work only on desktop with a mouse. You can still read the documentation on mobile, but to fully experience the ForesightJS mouse trajectory prediction, please try the demos on a desktop device.
This demo shows how ForesightJS improves on traditional loading strategies. All cards have a 300ms fetch delay to simulate loading data from a server.
On Hover
Loads when hovered
NOT LOADED
Hover to load data
Regular
Loads only when clicked
NOT LOADED
Click to load data
ForesightJS
Loads on predicted intent
NOT LOADED
Move your cursor toward this card