Reputation: 1734
We are considering Next.js for a web site we're building where the primary concern is performance. 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.
Initially, we began to build the site with Gatsby, then we learned that the ad API didn't play nicely with JavaScript UI frameworks. We're now considering whether Next.js might be more appropriate with its greater flexibility and features perhaps specifically helpful in our use case. (Our ad script is injected in the head between script
tags, and Next gives us some control with 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?
Upvotes: 1
Views: 872
Reputation: 2171
Maybe you can just reInit the ad script on each page load ?
Consider using a service like GTM to manage scripts.
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.
Upvotes: 1