--- title: How to load and optimize scripts nav_title: Scripts description: Optimize 3rd party scripts with the built-in Script component. related: title: API Reference description: Learn more about the next/script API. links: - app/api-reference/components/script --- {/* The content of this doc is shared between the app and pages router. You can use the `Content` component to add content that is specific to the Pages Router. Any shared content should not be wrapped in a component. */} ### Layout Scripts To load a third-party script for multiple routes, import `next/script` and include the script directly in your layout component: ```tsx filename="app/dashboard/layout.tsx" switcher import Script from 'next/script' export default function DashboardLayout({ children, }: { children: React.ReactNode }) { return ( <>
{children}
``` Or by using the `dangerouslySetInnerHTML` property: ```jsx