简体   繁体   English

Angular Router : Route Resolver 以及对 UX 的影响

[英]Angular Router : Route Resolver and the impact on the UX

I was wondering how to decide to use a route resolver to prefetch the required data for a given container (component).我想知道如何决定使用路由解析器来预取给定容器(组件)所需的数据。 If, in my case, the API is slow, the UX will suffer from the slow response.如果在我的情况下,API 很慢,那么 UX 将受到响应缓慢的影响。 The user will click the link, try to navigate to the route but the API call will still be active and the router will not resolve the route until the data has been fetched.用户将单击链接,尝试导航到路由,但 API 调用仍将处于活动状态,并且路由器将不会解析路由,直到获取数据。 Then, I can cache the data for subsequent route navigation.然后,我可以缓存数据以用于后续路线导航。

But the main question/discussion here is when to use the resolver (the ideal situation) and when to avoid it so the user isn't waiting after the response.但这里的主要问题/讨论是何时使用解析器(理想情况)以及何时避免它,以便用户不会在响应之后等待。 What is the best practice ?最佳做法是什么?

You can get about 300ms head start by preloading data when the user hovers the link/button.通过在用户悬停链接/按钮时预加载数据,您可以获得大约 300 毫秒的领先优势。

http://instantclick.io/click-test http://instantclick.io/click-test

What is the best practice ?最佳做法是什么?

It really depends on your app and its usage.这实际上取决于您的应用程序及其使用情况。 On most desktop app, it really isn't necessary.在大多数桌面应用程序中,确实没有必要。 I'd say the use case is for well thought UX.我会说用例是经过深思熟虑的用户体验。

A resolver is really useful for slow / mobile connections, It lets you gain a few ms.解析器对于慢速/移动连接非常有用,它可以让您获得几毫秒的时间。 But if the request takes 3 seconds, a resolver won't be enough to calm your user, you need to go deeper and follow "reactive web app" principles and do things like display the "skeleton" of your component and then your data when loaded.但是,如果请求需要 3 秒,解析器不足以让您的用户平静下来,您需要更深入地遵循“反应式 Web 应用程序”原则,并执行诸如显示组件的“骨架”,然后显示数据的操作加载。

A resolver will add some performances to your app, but it won't be enough of it for really slow connections.解析器将为您的应用程序增加一些性能,但对于非常慢的连接来说还不够。

As when to avoid it, I don't really see a case were better performances will be bad.至于什么时候避免它,我真的没有看到更好的表现会很糟糕的情况。 I guess sometimes the performances gain might not be really valuable and the time spent could be better use on something else.我想有时性能提升可能并不真正有价值,而花费的时间可以更好地用于其他事情。

IMO:海事组织:

  • Resolvers can be used for very tiny lite weight requests when you can be sure they will be processed quickly.当您确定它们会被快速处理时,解析器可用于非常小的轻量级请求。
  • But if you need to request some heavy information it is better to use ngOnInit with spinners or skeleton components ( demo (click "Reload with ghosts")).但是,如果您需要请求一些重要信息,最好将 ngOnInit 与微调器或骨架组件一起使用( 演示(单击“使用幽灵重新加载”))。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM