--- title: useScript() description: A powerful API for loading third-party scripts with optimized performance new: true --- The `useScript` composable provides an enhanced developer experience for loading third-party scripts with intelligent defaults for performance, security, and lifecycle management. ## Basic Usage ```ts import { useScript } from '@unhead/dynamic-import' const { onLoaded } = useScript('https://example.com/script.js') onLoaded(() => { // Script loaded successfully console.log('Script is ready to use') }) ``` ## Smart Defaults A singleton pattern is implemented so scripts with the same `src` or `key` are only loaded once globally. This helps prevent duplicate script loading and ensures consistent initialization. The following defaults are applied for optimal performance and security: - Scripts load after hydration by default - `defer`{lang="html"} enabled for proper execution order - `fetchpriority="low"`{lang="html"} to prioritize critical resources - `crossorigin="anonymous"`{lang="html"} prevents cookie access - `referrerpolicy="no-referrer"`{lang="html"} blocks referrer headers ## Input Options ### Simple URL Pass a URL string for the quickest implementation: ```ts import { useScript } from '@unhead/dynamic-import' useScript('https://example.com/script.js') ``` ### Full Configuration Pass an options object to customize any `