Skip to content

push-based/ngx-speculative-link

Folders and files

NameName
Last commit message
Last commit date

Latest commit

c392601 · Dec 13, 2024

History

22 Commits
Oct 19, 2024
Oct 19, 2024
Dec 13, 2024
Oct 19, 2024
Oct 19, 2024
Oct 19, 2024
Dec 13, 2024
Oct 19, 2024
Oct 19, 2024
Oct 19, 2024
Dec 9, 2024
Dec 9, 2024
Dec 9, 2024
Dec 5, 2024

Repository files navigation

NgxSpeculativeLink

An Angular implementation of Speculative Rules API inspired by quicklink and ngx-quicklink.

IMPORTANT This is currently in its discovery phase, there will be changes to the underlining implementation and its APIs.

How it works

NgxSpeculativeLink attempts so improve the performance of future navigation with preloading, prefetching and pre-rendering.

Under the hood it uses an IntersectionObserver to identify which links are in the viewport and are potential future navigations. Then using pattern matching we identify the routes connected to the link, preload the routes and execute a preResolverFunction when it enters the viewport.

Usage

Provide the Speculative Link Preloading Strategy to the router:

export const appConfig: ApplicationConfig = {
    providers: [
        // ... other providers
        provideRouter(appRoutes, withSpeculativeLinkPreloading()),
    ],
};

Add Speculative Link Functionality to an element:

<a href='/path' speculativeLink='/home'></a>

Add preResolver functionality to a route:

const route: Route = {
    path: ':event',
    data: {
        preResolver: (linkData: PreResolver) => {
            // Executed in the injection context of the route or the root
            inject(HomeResolver).preloadData(linkData);
        }
    }
}

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published