All Projects → mgechev → Ngx Quicklink

mgechev / Ngx Quicklink

Licence: mit
Quicklink prefetching strategy for the Angular router

Programming Languages

typescript
32286 projects

Projects that are alternatives of or similar to Ngx Quicklink

Fastify
Fast and low overhead web framework, for Node.js
Stars: ✭ 21,489 (+3567.06%)
Mutual labels:  performance, speed
Performance Improvements For Woocommerce
Performance tweaks for the front-end and back-end of a store.
Stars: ✭ 46 (-92.15%)
Mutual labels:  performance, speed
Bloom
🌸 HTTP REST API caching middleware, to be used between load balancers and REST API workers.
Stars: ✭ 553 (-5.63%)
Mutual labels:  performance, speed
React Pinpoint
An open source utility library for measuring React component render times.
Stars: ✭ 93 (-84.13%)
Mutual labels:  performance, speed
Flying Pages
Load inner pages instantly, intelligently
Stars: ✭ 169 (-71.16%)
Mutual labels:  performance, speed
Foxify
The fast, easy to use & typescript ready web framework for Node.js
Stars: ✭ 138 (-76.45%)
Mutual labels:  performance, speed
Quicklink
⚡️Faster subsequent page-loads by prefetching in-viewport links during idle time
Stars: ✭ 9,176 (+1465.87%)
Mutual labels:  performance, speed
Api
Minimal, extremely fast, lightweight Ruby framework for HTTP APIs
Stars: ✭ 252 (-57%)
Mutual labels:  performance, speed
Prerender.js
Fast webpages for all browsers.
Stars: ✭ 411 (-29.86%)
Mutual labels:  performance, speed
Vue Perf Devtool
Vue Performance Devtool is a browser extension for inspecting the performance of Vue Components.
Stars: ✭ 510 (-12.97%)
Mutual labels:  performance
Automon
Automon combines the power of AOP (AspectJ) with monitoring or logging tools you already use to declaratively monitor your Java code, the JDK, and 3rd party libraries.
Stars: ✭ 548 (-6.48%)
Mutual labels:  performance
Preact Pwa
Super fast progressive web app with small footprint & minimal dependancies
Stars: ✭ 507 (-13.48%)
Mutual labels:  performance
Sqlquerystress
SQL query stress simulator created by Adam Machanic http://dataeducation.com/sqlquerystress-the-source-code/
Stars: ✭ 508 (-13.31%)
Mutual labels:  performance
Ruby server timing
Bring Rails server-side performance metrics 📈 to Chrome's Developer Tools via the Server Timing API. Production Safe™.
Stars: ✭ 508 (-13.31%)
Mutual labels:  performance
Prosopite
🔍 Rails N+1 queries auto-detection with zero false positives / false negatives
Stars: ✭ 555 (-5.29%)
Mutual labels:  performance
Vue Virtual Collection
Vue component for efficiently rendering large collection data
Stars: ✭ 506 (-13.65%)
Mutual labels:  performance
React Adaptive Hooks
Deliver experiences best suited to a user's device and network constraints
Stars: ✭ 4,750 (+710.58%)
Mutual labels:  performance
Chillout
Reduce CPU usage by non-blocking async loop and psychologically speed up in JavaScript
Stars: ✭ 565 (-3.58%)
Mutual labels:  performance
Camerakit Android
Library for Android Camera 1 and 2 APIs. Massively increase stability and reliability of photo and video capture on all Android devices.
Stars: ✭ 5,131 (+775.6%)
Mutual labels:  performance
React Esi
React ESI: Blazing-fast Server-Side Rendering for React and Next.js
Stars: ✭ 537 (-8.36%)
Mutual labels:  performance

ngx-quicklink

quicklink implementation for Angular. It provides router preloading strategy which automatically downloads the lazy-loaded modules associated with all the visible links on the screen.

How it works

Quicklink attempts to make navigations to subsequent pages load faster. It:

  • Detects routerLinks within the viewport (using Intersection Observer)
  • Waits until the browser is idle (using requestIdleCallback)
  • Checks if the user isn't on a slow connection (using navigator.connection.effectiveType) or has data-saver enabled (using navigator.connection.saveData)
  • Prefetches the lazy loaded modules using Angular's prefetching strategy)

Why

This project aims to be a drop-in solution for sites to prefetch links based on what is in the user's viewport. It also aims to be small (~2KB minified/gzipped).

Usage

First you need to install the project:

npm i ngx-quicklink --save

After that import the QuicklinkModule to the AppModule, and use the QuicklinkStrategy as preloadingStrategy in the router's configuration. For example:

// ...
import { QuicklinkModule, QuicklinkStrategy } from 'ngx-quicklink';

@NgModule({
  declarations: [...],
  imports: [
    // ...
    QuicklinkModule,
    RouterModule.forRoot(routes, { preloadingStrategy: QuicklinkStrategy }),
  ],
  bootstrap: [...]
})
export class AppModule {}

If you want to add a route in the ignore list so that ngx-quicklink will not preload it use the data property:

export const routes: Routes = [
  {
    path: 'contact',
    loadChildren: import(() => './contact/contact.module').then(m => m.ContactModule),
    data: {
      preload: false
    }
  }
];

Note that to make the module available in lazy-loaded modules as well you need to import it in a shared module and export it. Look at this commit to see how ngx-quicklink is integrated in the angular-realworld-example-app.

For a demo, look at the example directory. To run the project use:

cd ngx-quicklink && npm i && npm run release
cd example && npm i && ng serve

Debugging

Not getting routes preloaded? Most likely the problem comes from a missing import of the QuicklinkModule. The QuicklinkModule exports a LinkDirective which matches the [routerLink] selector. It'll hook into all your router links in the scope of the module and observe their visibility. If you've not imported the QuicklinkModule correctly, this directive will be missing and the quicklink preloading strategy will not work.

How to verify Angular has made my links "quicklinks"? Inspect a router link and check if it has ngx-ql attribute. If it does not, make sure you import QuicklinkModule in the module that defines the compilation context of the template where the router link is. Alternatively, if the ngx-ql attribute is there, but the prefetching does not work as expected, please open an issue.

Polyfills

ngx-quicklink:

  • Includes a very small fallback for requestIdleCallback
  • Optionally requires IntersectionObserver to be supported (see CanIUse). On older browsers ngx-quicklink preloads all links on the page. If you want to enable the IntersectionObserver behavior on older browsers you can use conditional polyfill loading:
<script src="https://polyfill.io/v2/polyfill.min.js?features=IntersectionObserver"></script>

Alternatively, see the Intersection Observer polyfill.

FAQ

What's the difference between quicklink and ngx-quicklink?

quicklink prefetches the resource pointed by the href attribute of an anchor. This doesn't work for Angular because the value of the href attribute is not a JavaScript bundle but a path defined inside of the routing configuration. ngx-quicklink introduces some additional functionality to make the same strategy work well with Angular.

Should I use Guess.js or ngx-quicklink?

The prefetching behavior of Guess.js would most likely be more accurate compared to ngx-quicklink, which will reduce the overfetching. Guess.js, however, may take a little more effort to setup. In case you don't want to integrate with the analytics of your website ngx-quicklink is the right choice for you.

Contributors

mgechev wKoza rolaveric thekiba Flyrell Niaro
mgechev wKoza rolaveric thekiba Flyrell Niaro
krzysztof-grzybek retarsis mehmet-erim pshurygin jlilly
krzysztof-grzybek retarsis mehmet-erim pshurygin jlilly

License

MIT

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].