npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@pshurygin/ngx-quicklink

v0.2.4

Published

Quicklink for Angular

Downloads

4

Readme

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

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 |dependabot[bot] |wKoza |rolaveric |thekiba |Flyrell |

| | | | | :---: |:---: |:---: |:---: |:---: | Niaro |krzysztof-grzybek |maktarsis |mehmet-erim |jlilly |

License

MIT