Unverified Commit 5ec2f981 authored by Lachlan Campbell's avatar Lachlan Campbell Committed by GitHub

docs(next/script): Improve formatting of docs (#26149)

Noticed a few things off in the Script docs—for example, the "before" variant should show using a non-React Component `<script>` tag, & the capitalization was inconsistent in a few places.

## Documentation / Examples

- [x] Make sure the linting passes
parent c851da25
...@@ -12,7 +12,7 @@ Example of usage ...@@ -12,7 +12,7 @@ Example of usage
import Script from 'next/script' import Script from 'next/script'
// Before // Before
<Script <script
async async
src="https://www.google-analytics.com/analytics.js" src="https://www.google-analytics.com/analytics.js"
/> />
...@@ -36,28 +36,27 @@ Three loading strategies will be initially supported for wrapping third-party sc ...@@ -36,28 +36,27 @@ Three loading strategies will be initially supported for wrapping third-party sc
NOTE: above strategies work the same for inline scripts wrapped with ScriptLoader. NOTE: above strategies work the same for inline scripts wrapped with ScriptLoader.
Example scenarios ## Example scenarios
```js ```js
import Script from 'next/script' import Script from 'next/script'
// Loading polyfills before-interactive // Loading polyfills before-interactive
<Script <Script
src="https://polyfill.io/v3/polyfill.min.js?features=IntersectionObserverEntry%2CIntersectionObserver" src="https://polyfill.io/v3/polyfill.min.js?features=IntersectionObserverEntry%2CIntersectionObserver"
strategy="beforeInteractive" strategy="beforeInteractive"
></Script> />
// Lazy load FB scripts // Lazy load FB scripts
<Script <Script
src="https://connect.facebook.net/en_US/sdk.js" src="https://connect.facebook.net/en_US/sdk.js"
strategy="lazyOnload" strategy="lazyOnload"
></Script> />
// Use the onLoad callback to execute code on script load // Use the onLoad callback to execute code on script load
<Script id="stripe-js" src="https://js.stripe.com/v3/" onLoad={() => { <Script id="stripe-js" src="https://js.stripe.com/v3/" onLoad={() => {
this.setState({stripe: window.Stripe('pk_test_12345')}); this.setState({stripe: window.Stripe('pk_test_12345')});
}}></Script> }} />
// Loading strategy works for inline scripts too // Loading strategy works for inline scripts too
<Script strategy="lazyOnload"> <Script strategy="lazyOnload">
...@@ -78,7 +77,7 @@ import Script from 'next/script' ...@@ -78,7 +77,7 @@ import Script from 'next/script'
id="analytics" id="analytics"
nonce="XUENAJFW" nonce="XUENAJFW"
data-test="analytics" data-test="analytics"
></Script> />
``` ```
## Which third-party scripts to wrap with Script Loader ## Which third-party scripts to wrap with Script Loader
...@@ -89,4 +88,4 @@ We recommend the following Script Loader strategies for these categories of thir ...@@ -89,4 +88,4 @@ We recommend the following Script Loader strategies for these categories of thir
| ----------------- | -------------------------------------------------------------------------------------------- | | ----------------- | -------------------------------------------------------------------------------------------- |
| beforeInteractive | polyfill.io<br>Bot detection, security & authentication<br>User consent management (GDPR) | | beforeInteractive | polyfill.io<br>Bot detection, security & authentication<br>User consent management (GDPR) |
| afterInteractive | Tag-managers<br>Analytics | | afterInteractive | Tag-managers<br>Analytics |
| lazyOnload | customer relationship management eg. Google feedback, chat support widget<br>social networks | | lazyOnload | Customer relationship management eg. Google feedback, chat support widget<br>Social networks |
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment