ForesightJS: Intent-Based Prefetching for Web Apps
Lightweight JavaScript library that predicts user intent based on mouse movements and keyboard navigation. Perfect for smart prefetching. Also works for mobile!
At a glance
- What is it?
- ForesightJS is a TypeScript library that uses pointer, keyboard, scroll, viewport, and touch signals to prefetch likely destinations. It fits sites that can trade some speculative network work for earlier page loading, but it is not a route framework or a complete caching policy.
- Who is it for?
- Web teams with identifiable links, navigation targets, and measurable server capacity should evaluate ForesightJS on pages where early requests would save time. Projects that cannot tolerate speculative traffic, pages without predictable destinations, or applications needing an end-to-end routing and cache policy should choose a different approach.
- Can I use it commercially?
- Yes. MIT is a permissive licence: you can use, modify and sell software built on it, as long as you keep its copyright and licence notices.
- Is it still maintained?
- Yes. The repository last received commits 2 days ago.
- What is it written in?
- Mainly TypeScript, according to GitHub's language statistics.
Answers come from the project's GitHub data, last synced on October 22, 2026, and from our analysis. They are not legal advice.
Editorial analysis
Why ForesightJS Adds Prefetching Before Navigation
ForesightJS addresses the gap between a link becoming a likely destination and the browser beginning its normal navigation request. Conventional prefetching often depends on explicit rules such as links in the viewport, while ForesightJS watches interaction signals that can indicate intent sooner. Its goal is to make content available before the user commits to navigation.
The project is aimed at web teams that want a framework-independent way to improve perceived loading speed. The README says the core works without configuration and supports desktop and mobile devices. Official bindings are listed for React, Vue, Angular, and Astro. Teams using Svelte, Solid, or another framework are directed to the Other Frameworks documentation for building a thin binding over the core.
This is a focused library rather than an application router. It does not replace navigation state, route matching, cache invalidation, request deduplication, or server-side prefetch policy. The useful question is whether an application can turn a probable destination into the correct prefetch operation. ForesightJS supplies intent signals, while the host application still owns the resource-loading decision.
Desktop, Mobile, and Framework-Specific Prediction Paths
On desktop and for keyboard users, ForesightJS uses mouse trajectory prediction, keyboard navigation tracking, and scroll-based prefetching. These paths cover different actions. A pointer approaching a target can indicate interest before a click, keyboard navigation can reveal movement toward an interactive element, and scrolling can expose content that an application may need to fetch.
Mobile behavior is different by design. The documented mobile strategies are viewport enter detection and touch start events, with `touchDeviceStrategy` listed as configurable. This distinction matters because mouse trajectory prediction does not describe touch interaction well. A mobile implementation based on the same mechanism as a desktop cursor would ignore the device model described by the project.
The repository separates the core from framework integrations. `js.foresight` is the framework-agnostic package. `@foresightjs/react` exposes `useForesight`, the `Foresight` component, and `useForesightEvent`, with documentation for Next.js and React Router. Vue provides a `v-foresight` directive, a `Foresight` component, and composables. Angular lists a directive, service, component, and injection helper. Astro adds Foresight as a fifth prefetch strategy beside its native four, plus `<ForesightLink>` and `registerForesight`. These package boundaries indicate that prediction is not tied to one rendering model.
Installing ForesightJS and Choosing the Correct Binding
The README directs framework-agnostic users to the Quick Start documentation and sends framework users to package-specific installation pages. It does not include a core-package installation command or a complete initialization example, so this review does not invent one. Choose the documented package for the rendering stack rather than installing every binding.
The repository does provide an exact installation command for its separate development package. Add that package when the goal is to inspect prediction behavior during development:
pnpm add js.foresight-devtoolsThe README says this standalone package uses Foresight Events and provides real-time visualization of mouse trajectory predictions, element bounds, and callback execution. It also links to dedicated debugging documentation for setup details not included here. Users should expect the normal browser experience to remain visually unchanged unless this development package is enabled. The README describes that visibility through the ForesightJS DevTools rather than through permanent interface elements.
For contributors working in the monorepo itself, the root scripts expose build and test commands. These are repository workflows, not application installation instructions:
pnpm buildThe root `package.json` defines `build` as a filtered command for `js.foresight*` and `@foresightjs/*` packages. The repository is a pnpm workspace with package sources under `packages/`, shared TypeScript settings in `tsconfig.base.json`, and Changesets for versioning and releases.
Registration, Configuration, and Event Boundaries
ForesightJS is documented as configurable globally and per element, although the README does not reproduce the option names beyond the mobile `touchDeviceStrategy` setting. This is an important documentation boundary for adoption. The library can operate out of the box, but teams that need custom thresholds, eligible elements, or mobile behavior must consult the linked configuration pages before assuming which defaults apply.
The explicit Foresight Events system is used by the development tools. The README describes those events as the basis for visualizing predictions, element bounds, and callbacks. Framework bindings also expose event-oriented APIs, including `useForesightEvent` in React, `useForesightEvent` in Vue, and `injectForesightEvent` in Angular. The presence of events creates a useful inspection point: an application team can examine when ForesightJS considers an element relevant instead of treating prefetching as an unexplained side effect.
The README does not document callback signatures, event payload schemas, cancellation semantics, deduplication behavior, or a rollback procedure. It also does not claim that a predicted destination is guaranteed to be visited. Engineers should therefore validate the binding documentation and application-level loader together. ForesightJS may predict intent, but the integration still needs a defined response to that prediction.
Network Trade-Offs and Cases Where Prediction Is Misapplied
The clearest limitation is also the defining feature: prefetching is speculative. Mouse, keyboard, scroll, viewport, and touch signals can identify likely interest without proving that navigation will occur. An implementation may therefore request resources that are never needed. The README does not provide traffic controls, cache limits, retry behavior, or server protection guidance, so those concerns cannot be treated as built-in features.
ForesightJS is a poor fit for a page with no meaningful prefetchable destinations, such as a static screen with no links or data transitions. It is also the wrong abstraction when the application needs to prefetch authenticated, personalized, or mutation-sensitive resources but has no policy for exposing or discarding those responses. Prefetching alone cannot solve those data and cache questions.
There is a similar mismatch with navigation libraries that already make explicit prefetch decisions. Rather than compare this project to a named competitor without documented technical differences, the useful alternative is rule-based viewport or link prefetching. That approach selects known resources based on markup and visibility. ForesightJS adds interaction-based prediction, which can cover keyboard and pointer intent, but introduces more speculative behavior. Applications already performing controlled route prefetch may gain little from adding another prediction layer.
The development package is particularly relevant during evaluation because it exposes prediction, bounds, and callback execution. That visibility can reveal excessive or mistimed requests, but the README does not claim it measures wasted bandwidth or production cache pressure. Those outcomes require application-level observation.
Release Cadence, MIT Terms, and Integration Upgrades
The repository is not archived. Its last push was on 2026-10-10. Recent releases include `[email protected]` and `[email protected]`, both dated 2026-07-08, followed by the `V4.2.0` release described as introducing the `<Foresight>` component on 2026-06-13. These facts indicate recent repository activity, but the README does not publish a support policy or a long-term compatibility schedule.
The repository uses Changesets. Its root scripts include `changeset`, `version-packages`, and a release command that runs a production build before `changeset publish`. Multiple package families mean adoption can involve more than one version stream. A team using the core, a framework adapter, and development tools should check compatibility documentation for each selected package before upgrading them together.
The project is distributed under the MIT License. That permits use, modification, distribution, and sublicensing subject to the license terms, while requiring preservation of the copyright and license notice. This is a practical licensing statement rather than legal advice. Projects with organization-specific policies should have their own process review the `LICENSE` file and any dependency notices.
Editorial conclusion
Web teams with identifiable links, navigation targets, and measurable server capacity should evaluate ForesightJS on pages where early requests would save time. Projects that cannot tolerate speculative traffic, pages without predictable destinations, or applications needing an end-to-end routing and cache policy should choose a different approach. Verify first that the correct framework package is documented for the chosen integration and that the linked development tools can expose prediction and callback behavior in the actual application.
Frequently asked questions
Does ForesightJS support mobile devices?
Yes. The README states that mobile users are supported through viewport enter detection and touch start events, with mobile behavior configurable through `touchDeviceStrategy`.
Which frameworks have official ForesightJS integrations?
The README lists official packages for React, Vue, Angular, and Astro. Other frameworks can use the framework-agnostic core or follow the documented approach for building a thin binding.
How can I inspect ForesightJS predictions during development?
The standalone `js.foresight-devtools` package provides real-time views of mouse trajectory predictions, element bounds, and callback execution through Foresight Events.
Official sources
Add this badge to your README
If you maintain this project, the badge below links readers to this analysis and shows its maintenance status from the daily GitHub snapshot. Paste the markdown into your README; add ?metric=license or ?metric=stars to the image URL for a different field.
[](https://hysenlabs.com/projects/spaansba-foresightjs)Was this useful?