next/script using beforeInteractive strategy don't work with alert
See original GitHub issueWhat version of Next.js are you using?
11.0.0
What version of Node.js are you using?
14.17.0
What browser are you using?
Chrome
What operating system are you using?
macOS
How are you deploying your application?
next start
Describe the Bug
When I try to add next/script into “_document” or “_app” files calling a inline alert function, don’t work using beforeInteractive strategy, but when I don’t explicitly inform a strategy value, it works.
Expected Behavior
Should work with beforeInteractive strategy inside _document.js or _app.js.
To Reproduce
Just add <Script strategy="beforeInteractive">{`alert('Not work')`}</Script>
to _document.js or _app.js, and try to run with next build && next start
.
Issue Analytics
- State:
- Created 2 years ago
- Reactions:4
- Comments:29 (15 by maintainers)
Top Results From Across the Web
Basic Features: Handling Scripts - Next.js
Optimize your third-party scripts with the built-in `next/script` component. ... Note: The worker strategy is not yet stable and does not yet work...
Read more >Why does the next.js Script tag with the beforeInteractive ...
js Script tag with the strategy beforeInteractive works. For testing i just used lodash. But i keep getting a ReferenceError: _ is not...
Read more >Script Loading, performance and Next Script
Using Next Script is easy, deciding which strategy to use is hard. Harder than just sticking the script somewhere anyway. beforeInteractive.
Read more >Best practices to increase the speed for Next.js apps
By setting the value of the strategy prop in the next/script component, you can use three different script loading approaches: afterInteractive ...
Read more >NextJS Core Web Vitals - fix third party scripts
The Next.js Script component, next/script , is an extension of the HTML <script> ... The beforeInteractive strategy should only be used on scripts...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
seems the narrative has changed regarding this in the doc: https://nextjs.org/docs/basic-features/script#beforeinteractive
It is stated that:
This strategy only works inside _document.js
However, if you try with their example, it does not work at all:
Put it in the app does work.
I am curious why
Another use-case is a code that detects user selected light / dark theme, to avoid flickering on the first load.