From 43116222642f8be0be88f0566f18bf89c8115ef9 Mon Sep 17 00:00:00 2001 From: Janicklas Ralph James Date: Tue, 25 May 2021 13:59:18 -0700 Subject: [PATCH 1/6] Script component docs --- docs/basic-features/script.md | 47 +++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 docs/basic-features/script.md diff --git a/docs/basic-features/script.md b/docs/basic-features/script.md new file mode 100644 index 0000000000000..dc1cb97285923 --- /dev/null +++ b/docs/basic-features/script.md @@ -0,0 +1,47 @@ +--- +description: Next.js supports built-in third-party Script loading optimization +--- + +# Script Component + +Since version **10.2**, Next.js has built-in Script component. + +Example of usage + +```js +import Script from 'next/script' + +// Before + + +// Lazy load FB scripts + + +// Use the onLoad callback to execute code on script load + + +// Loading strategy works for inline scripts too + + +// or + +``` + +## Which third-party scripts to wrap with Script Loader + +We recommend the following Script Loader strategies for these categories of third-party scripts -| Loading strategy | 3P categories | -| ------------------ | -------------------------------------------------------------------------------------------- | -| before-interactive | polyfill.io
Bot detection, security & authentication
User consent management (GDPR) | -| after-interactive | Tag-managers
Analytics | -| lazy-onload | customer relationship management eg. Google feedback, chat support widget
social networks | +| Loading strategy | 3P categories | +| ----------------- | -------------------------------------------------------------------------------------------- | +| beforeInteractive | polyfill.io
Bot detection, security & authentication
User consent management (GDPR) | +| afterInteractive | Tag-managers
Analytics | +| lazyOnload | customer relationship management eg. Google feedback, chat support widget
social networks | diff --git a/test/integration/script-loader/pages/_document.js b/test/integration/script-loader/pages/_document.js index d0b9a63d3a4a1..930580e96dd83 100644 --- a/test/integration/script-loader/pages/_document.js +++ b/test/integration/script-loader/pages/_document.js @@ -30,11 +30,6 @@ export default class MyDocument extends Document { src="https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.20/lodash.min.js?a=documentLazyOnload" strategy="lazyOnload" > - + +// All script attributes are forwarded to the final element + ``` ## Which third-party scripts to wrap with Script Loader From 53fdcd15d11450008d23325e1b5dc5ff3165a6c8 Mon Sep 17 00:00:00 2001 From: Janicklas Ralph James Date: Mon, 14 Jun 2021 13:07:36 -0700 Subject: [PATCH 5/6] Update text --- docs/basic-features/script.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/basic-features/script.md b/docs/basic-features/script.md index 3a319df6310f0..12ce5d2ee2a4b 100644 --- a/docs/basic-features/script.md +++ b/docs/basic-features/script.md @@ -1,5 +1,5 @@ --- -description: Next.js supports built-in third-party Script loading optimization +description: Next.js helps you optimize loading third-party scripts with the built-in next/script component. --- # Script Component From fee393f7fc1451ec4ea2b78be494665e856e9072 Mon Sep 17 00:00:00 2001 From: JJ Kasper Date: Tue, 15 Jun 2021 09:14:35 -0500 Subject: [PATCH 6/6] Apply suggestions from code review --- docs/basic-features/script.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/basic-features/script.md b/docs/basic-features/script.md index 12ce5d2ee2a4b..ba9f45c9e63af 100644 --- a/docs/basic-features/script.md +++ b/docs/basic-features/script.md @@ -4,7 +4,7 @@ description: Next.js helps you optimize loading third-party scripts with the bui # Script Component -Since version **11**, Next.js has built-in Script component. +Since version **11**, Next.js has a built-in Script component. Example of usage @@ -32,7 +32,7 @@ Three loading strategies will be initially supported for wrapping third-party sc - script is fetched and executed _after_ page is interactive (i.e. after self-bundled javascript is executed) - script is injected during hydration and will execute soon after hydration - lazyOnload - - script is injected at onload, and will execute in a subsequent idle period (using rIC) + - script is injected at onload, and will execute in a subsequent idle period (using `requestIdleCallback`) NOTE: above strategies work the same for inline scripts wrapped with ScriptLoader. @@ -85,7 +85,7 @@ import Script from 'next/script' We recommend the following Script Loader strategies for these categories of third-party scripts -| Loading strategy | 3P categories | +| Loading strategy | third-party categories | | ----------------- | -------------------------------------------------------------------------------------------- | | beforeInteractive | polyfill.io
Bot detection, security & authentication
User consent management (GDPR) | | afterInteractive | Tag-managers
Analytics |