[我知道Gatsby使用代码拆分来优化每个给定页面的包,但是当将页面创建为单页面应用程序时(如Client-only routes中提到的,我们如何处理它。
[例如,如果一条路线比较昂贵,我们也可以在这些情况下使用代码拆分吗?
您应该阅读其博客文章的this segment。这里是重要的部分:
gatsby-link和link rel =“ prefetch”
由gatsby导出的Link组件附带一个IntersectionObserver。行为是双重的:
An IntersectionObserver is registered for all links This will register an idle prefetch for a request for that link’s resources See the code for gatsby-link On hover a fetch will be used to send a non-idle request for that link’s resources This will use an onMouseEnter prop to make the resources available via our internal loader See the code for gatsby-link
解决方案非常简单:
[使用经典HTML a标签而不是Gatsby Link。
通过这种方式,Gatsby项目维护者禁用了预取,如本issuee中所讨论的。