There is a common understanding that when a module is imported multiple times within a JavaScript program, it only executes once during the first import.
Informative article:
The concept is straightforward: each module is evaluated just once, meaning the module-level scope is only executed once. Subsequent imports of the same module skip re-evaluation and make use of the previously resolved exports.
This explains why code placed above a React component runs only once, as mentioned in the official documentation:
Certain logic should be executed only once when the application starts. By placing it outside your components...it ensures that this specific logic runs just once after the page loads in the browser.
My inquiry pertains to Next.js on Vercel:
Do imports run only once when the site is built, and not again thereafter?
Or does this behavior vary between static and dynamic routes (pages)? For example, a static page may execute an import only during build time, while a dynamic route triggers the import every time the page is visited in a browser?