5

In an angularJS app there is quite a big of latency between the user and the server (also bandwidth may be limited), so when the user requests a new page, it has to wait about 2-500ms for it to load.

I'm thinking of "preloading" model data, templates, scripts in the background, but intend to do so ONLY if there is no page requested by the user. If the user requests one specific page I'd like to stop the preloading process and load the resources explicitly requested by the user.

So my question boils down to:

  • Is there a way to make an ajax request "ONLY IF" there is no network activity?
  • Is there a way to "pause" currently running ajax requests? or
  • Is there a way to prioritize ajax requests?

Thanks,

Ákos Vandra-Meyer
  • 1,890
  • 1
  • 23
  • 40

2 Answers2

0

Seems like https://nicedoc.io/pastelsky/network-idle-callback will be helpful for you.

It uses serviceWorker to observe network calls, and dispatch event when it senses network idle.

npm install network-idle-callback

Usage

Eylon Sultan
  • 936
  • 9
  • 16
-1

Sounds like requestidlecallback is what you're looking for. There's also a package built on top that exposes an event you can listen to: https://github.com/choojs/on-idle

milan
  • 11,872
  • 3
  • 42
  • 49