question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

External scripts added with `next/script` load only once

See original GitHub issue

What version of Next.js are you using?

12.0.2

What version of Node.js are you using?

14.17.6

What browser are you using?

Chrome, Safari, Firefox

What operating system are you using?

macOS

How are you deploying your application?

Vercel

Describe the Bug

While trying to integrate external scripts with next/script, I noticed that they load only once on a page or component mount. I’ve created a quick demo to describe it more visually.

Expected Behavior

I expect the status to turn green every time I visit the page using website navigation links without reloading.

To Reproduce

Source

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:11
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
ndekrosscommented, Feb 15, 2022

Thank you for looking into this!

Quick question: Would you prefer if this was the default behavior for every <Script> added to a page, regardless of strategy, or instead have a separate prop to enable this? I think the former makes more sense, but would like to hear if you have a different opinion 😃

Yes, making the script load every time should be default as it’s expected with vanilla JS.

0reactions
github-actions[bot]commented, Dec 22, 2022

This closed issue has been automatically locked because it had no new activity for a month. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Basic Features: Handling Scripts - Next.js
This script will load and execute when any route in your application is accessed. Next.js will ensure the script will only load once,...
Read more >
Next.js inline script only loads once - Stack Overflow
Here are the steps to adding tiny-slider to a next.js app. Add a pages/_document.js to load the styles. // pages/_document.js import { Html, ......
Read more >
next/script onLoad run once per cache Key (id, src) #30962
I just need same feature (fire onLoad every time, when script is added to attach some event listener). Any news here? Meanwhile I...
Read more >
Optimizing third-party script loading in Next.js
This article discusses the Next.js Script component and demonstrates how it can be used for better sequencing of third-party scripts.
Read more >
The Script component in Next.js? - Medium
The nextjs script component onLoad property takes a function as a value. You pass arrow or regular function it bases on the requirement....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found