[英]How to pre-load data in the background (Angular Web App)
Our (Angular) app uses ~15 APIs to get data from the backend.我们的(Angular)应用程序使用约 15 个 API 从后端获取数据。 Each API is used to get data for a specific page.每个 API 用于获取特定页面的数据。 The APIs are not very fast unfortunately, some of them take 5-10 seconds to return.不幸的是,API 不是很快,其中一些需要 5-10 秒才能返回。 The amount of data that we get is about 1 MB for all pages.对于所有页面,我们获得的数据量约为 1 MB。 Some pages might not be used every day but several of them are guaranteed to be used all the time.有些页面可能不会每天都使用,但其中一些页面保证会一直使用。
Considering all of these, I am thinking to preload (almost) all the data in the background when the app starts, so when a page is loaded we won't wait for 5-10 seconds for the data.考虑到所有这些,我正在考虑在应用程序启动时在后台预加载(几乎)所有数据,这样当加载页面时我们不会等待 5-10 秒的数据。
The way I am thinking to do that is: when the app starts, wait for 10 seconds or so and then call all the APIs and save the data in the store (NGRX).我想这样做的方式是:当应用程序启动时,等待 10 秒左右,然后调用所有 API 并将数据保存在商店 (NGRX) 中。 However I have a few questions:但是我有几个问题:
I ended up implementing a 'can-load-in-the-background-trigger' (Subject) that is triggered by each page after it received the data.我最终实现了一个“can-load-in-the-background-trigger”(主题),它在每个页面收到数据后触发。 Only when this trigger is true I start loading the rest of the data in the background.只有当这个触发器为真时,我才开始在后台加载数据的 rest。
This way I mitigated issue-#1, but I would still like to get some answers if possible.这样我就缓解了问题#1,但如果可能的话,我仍然想得到一些答案。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.