I am building a website with Angular2 that consists of multiple pages containing a dashboard with various statistics.
On a single page, 6 different requests are made separately (one for each dashboard tile), which can take up to 5 seconds to conclude. The problem appears when I change the page whilst the requests for the dashboard are ongoing.
On this situation, the requests will start to stack up, and if I change the page multiple times the dashboards will take more and more time to be loaded. Each request is made the following way:
return this.http.post("http://mywebsite.com/dashboard/info", body, options)
.map((res) => {
return res.json()
}).subscribe((result) => { /* do something */});
What I am looking for is for a way to abort all of the ongoing requests when I change the page, to avoid that they stack up and cause excessive loading times.