diff --git a/docs/api-reference/next/image.md b/docs/api-reference/next/image.md index 958a3e116e32..957e53c43917 100644 --- a/docs/api-reference/next/image.md +++ b/docs/api-reference/next/image.md @@ -119,9 +119,11 @@ const MyImage = (props) => { A string that provides information about how wide the image will be at different breakpoints. Defaults to `100vw` (the full width of the screen) when using `layout="responsive"` or `layout="fill"`. -`sizes` is important for performance when using `layout="responsive"` or `layout="fill"` with images that take up less than the full viewport width. +If you are using `layout="fill"` or `layout="responsive"`, it's important to assign `sizes` for any image that takes up less than the full viewport width. -If you are using `layout="fill"` or `layout="responsive"` and the image will always be less than half the viewport width, include `sizes="50vw"`. Without `sizes`, the image will be sent at twice the necessary resolution, decreasing performance. +For example, when the parent element will constrain the image to always be less than half the viewport width, use `sizes="50vw"`. Without `sizes`, the image will be sent at twice the necessary resolution, decreasing performance. + +If you are using `layout="intrinsic"` or `layout="fixed"`, then `sizes` is not needed because the upperbound width is constrained already. [Learn more](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/img#attr-sizes). diff --git a/docs/api-reference/next/script.md b/docs/api-reference/next/script.md new file mode 100644 index 000000000000..49fe558c6b16 --- /dev/null +++ b/docs/api-reference/next/script.md @@ -0,0 +1,70 @@ +--- +description: Optimize loading of third-party scripts with the built-in Script component. +--- + +# next/script + +
+ Examples + +
+ +
+ Version History + +| Version | Changes | +| --------- | ------------------------- | +| `v11.0.0` | `next/script` introduced. | + +
+ +> **Note: This is API documentation for the Script Component. For a feature overview and usage information for scripts in Next.js, please see [Script Optimization](/docs/basic-features/script.md).** + +## Optional Props + +### src + +A path string specifying the URL of an external script. This can be either an absolute external URL or an internal path. + +### strategy + +The loading strategy of the script. + +| `strategy` | **Description** | +| ------------------- | ---------------------------------------------------------- | +| `beforeInteractive` | Load script before the page becomes interactive | +| `afterInteractive` | Load script immediately after the page becomes interactive | +| `lazyOnload` | Load script during browser idle time | + +### onLoad + +A method that returns additional JavaScript that should be executed after the script has finished loading. + +The following is an example of how to use the `onLoad` property: + +```jsx +import { useState } from 'react' +import Script from 'next/script' + +export default function Home() { + const [stripe, setStripe] = useState(null) + + return ( + <> + ``` +Or by using the `dangerouslySetInnerHTML` property: + +```jsx + - -// or - -