Snippets are blocks of code shared at the site level that can be added to your pages. Code that is not visual, such as Google Analytics, Facebook pixels, or custom CSS, should be placed into snippets. We recommend using separate snippets for each block of code to keep things flexible and easy to find.
<head>
or end of the closing <body>
. If you’re unsure which to choose, please check with the code’s documentation. Lastly, select whether or not to automatically include this snippet when new pages are created.
—
found on each snippet row.
next/script
to add snippets directly to your codebase. Using next/script
in Next.js is beneficial because it optimizes the loading of third-party scripts, ensuring they don’t block the main thread and improving page performance. It also allows for fine-grained control over script loading behavior, such as lazy loading or loading only after the page has rendered, enhancing the overall user experience.