Giter Site home page Giter Site logo

mgechev / ngx-hover-preload Goto Github PK

View Code? Open in Web Editor NEW
159.0 3.0 6.0 207 KB

๐Ÿ–ฑ Preload Angular lazy-loaded routes on mouse over

JavaScript 13.23% TypeScript 84.16% HTML 2.30% CSS 0.31%
angular javascript typescript web-performance prefetching preloading

ngx-hover-preload's Introduction

mgechev

ngx-hover-preload

This package exports a PreloadingStrategy, which will preload a lazy-loaded route on mouse over a corresponding router link.

Alternatives

Other preloading strategies:

  • ngx-quicklink - Preloads the modules associated with all links visible in the viewport. Quicklink does more aggressive preloading compared to ngx-hover-preload, which makes it more network and CPU intensive.
  • Guess.js - Most advanced preloading strategy, which uses predictive prefetching. At build-time Guess.js compiles a data analytics model and includes it in your production bundle, so that at runtime after each navigation Guess.js prefetches only the modules that are likely to be needed next. Guess.js works particularly well with ngx-hover-preload, because if the prediction was wrong the preloading mechanism gracefully fallbacks to hover.

Example

Example is available here.

Usage

Install the module:

yarn add ngx-hover-preload

Import the HoverPreloadModule in your AppModule and your lazy-loaded modules to ensure the required directives are available:

// ...
import { HoverPreloadModule } from 'ngx-hover-preload';

@NgModule({
  declarations: [
    // ...
  ],
  imports: [
    // ...
    HoverPreloadModule
  ],
  bootstrap: [AppComponent]
})
export class AppModule { }

Make sure you import the HoverPreloadModule in all lazy-loaded modules in which you want to have this functionality available

Don't forget to set the HoverPreloadStrategy as your preloadStrategy:

// ...
import { HoverPreloadStrategy } from 'ngx-hover-preload';

@NgModule({
  // ...
  imports: [RouterModule.forRoot(routes, { preloadingStrategy: HoverPreloadStrategy })],
})
export class AppModule {} // or AppRoutingModule

License

MIT

ngx-hover-preload's People

Contributors

darxx avatar mgechev avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

ngx-hover-preload's Issues

StaticInjectorError

Hi,

I am getting the following error when following your instructions on Angular 8:

 NullInjectorError: StaticInjectorError(AppModule)[LinkDirective -> RegistryService]: 

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.