简体   繁体   English

Next.js 全DOM刷新每页加载

[英]Next.js Full DOM Refresh Every Page Load

We are considering Next.js for a web site we're building where the primary concern is performance.我们正在考虑 Next.js 用于我们正在构建的 web 站点,其中主要关注的是性能。 The site must be able to run ads, however, and this specific ad network's API requires a full DOM refresh on each page load.但是,该站点必须能够运行广告,并且此特定广告网络的 API 需要在每次页面加载时进行完整的 DOM 刷新。

Initially, we began to build the site with Gatsby, then we learned that the ad API didn't play nicely with JavaScript UI frameworks.最初,我们开始使用 Gatsby 构建网站,然后我们了解到广告 API 不能很好地与 JavaScript UI 框架配合使用。 We're now considering whether Next.js might be more appropriate with its greater flexibility and features perhaps specifically helpful in our use case.我们现在正在考虑 Next.js 是否更合适,因为它具有更大的灵活性和可能对我们的用例特别有用的特性。 (Our ad script is injected in the head between script tags, and Next gives us some control with next/script.) (我们的广告脚本被注入到script标签之间的头部,Next 给了我们一些使用 next/script 的控制权。)

My question here is essentially twofold:我的问题基本上是双重的:

First, is the above possible?首先,以上可能吗? Second, would it negate any performance benefits of using Next.js in the first place?其次,它首先会否定使用 Next.js 的任何性能优势吗?

Maybe you can just reInit the ad script on each page load?也许您可以在每个页面加载时重新启动广告脚本?

Consider using a service like GTM to manage scripts.考虑使用像 GTM 这样的服务来管理脚本。

Then you can fire events on each router change in your app, intercept theses events in GTM and trigger actions (script init or add a new instance) directly in GTM.然后,您可以在应用程序中的每个路由器更改时触发事件,在 GTM 中拦截这些事件并直接在 GTM 中触发操作(脚本初始化或添加新实例)。

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

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