---
title: "useScriptTriggerIdleTimeout() · Nuxt Scripts"
description: "Load a script after Nuxt is ready and an idle timeout has elapsed."
canonical_url: "https://scripts.nuxt.com/docs/api/use-script-trigger-idle-timeout"
meta:
  "og:description": "Load a script after Nuxt is ready and an idle timeout has elapsed."
  "og:image": "https://scripts.nuxt.com/_og/s/o_d57351d50bc4b204.png"
  "og:image:height": "600"
  "og:image:type": image/png
  "og:image:width": "1200"
  "og:title": "useScriptTriggerIdleTimeout() · Nuxt Scripts"
  "twitter:image": "https://scripts.nuxt.com/_og/s/o_d57351d50bc4b204.png"
---

> Index of every page on this site: [llms.txt](https://scripts.nuxt.com/llms.txt)

**Api**

# **useScriptTriggerIdleTimeout()**

[Copy for LLMs](https://scripts.nuxt.com/docs/api/use-script-trigger-idle-timeout.md)

Load a noncritical script after Nuxt is ready and the configured idle timeout has elapsed.

The trigger uses a timer after `**onNuxtReady**`; it does not wait for the browser's `**requestIdleCallback**`.

## Signature

```ts
function useScriptTriggerIdleTimeout(options: IdleTimeoutScriptTriggerOptions): UseScriptTrigger
```

## Arguments

```ts
export interface IdleTimeoutScriptTriggerOptions {
  /**
   * The timeout in milliseconds to wait before loading the script.
   */
  timeout: number
}
```

## Returns

An Unhead trigger function for `**scriptOptions.trigger**`. It starts the timer after Nuxt is ready and loads the script when the timeout completes. Disposing the consumer scope cancels the pending timer, including when disposal happens before Nuxt becomes ready. The trigger does not install a timer during SSR.

## Nuxt Config Usage

Registry entries and global scripts accept the trigger directly in `**nuxt.config**`:

```ts
export default defineNuxtConfig({
  scripts: {
    registry: {
      googleAnalytics: {
        id: 'GA_MEASUREMENT_ID',
        trigger: { idleTimeout: 3000 } // Load 3 seconds after Nuxt ready
      }
    }
  }
})
```

## Examples

### Basic Usage

Load a script 5 seconds after Nuxt is ready:

```ts
const script = useScript({
  src: 'https://example.com/analytics.js',
}, {
  trigger: useScriptTriggerIdleTimeout({ timeout: 5000 })
})
```

### Delayed Analytics Loading

Delay analytics that does not need to load immediately:

```vue
<script setup lang="ts">
// Load Google Analytics after a 3-second delay
const { status } = useScriptGoogleAnalytics({
  id: 'GA_MEASUREMENT_ID',
  scriptOptions: {
    trigger: useScriptTriggerIdleTimeout({ timeout: 3000 })
  }
})

// The registry sends its initial page view when the delayed tag initializes.
watch(status, (value) => {
  if (value === 'loaded') {
    console.log('Google Analytics loaded')
  }
})
</script>
```

### Delay Nonessential UI

Give critical resources a head start before loading widgets and search helpers:

```vue
<script setup lang="ts">
// Load chat widget after 10 seconds
const chatScript = useScript({
  src: 'https://widget.intercom.io/widget/abc123'
}, {
  trigger: useScriptTriggerIdleTimeout({ timeout: 10000 })
})

// Load search enhancement after 5 seconds
const searchScript = useScript({
  src: 'https://cdn.example.com/search-enhancement.js'
}, {
  trigger: useScriptTriggerIdleTimeout({ timeout: 5000 })
})
</script>
```

## Choosing a Timeout

- Pick a delay for the feature, not a site-wide default.
- Shorten it when users are likely to need the feature early.
- Measure Core Web Vitals to confirm that the delay helps.
- A script accepts one trigger. Use a custom promise to race a timeout against an interaction.

[Edit this page](https://github.com/nuxt/scripts/edit/main/docs/content/3.api/3.use-script-trigger-idle-timeout.md)

[Markdown For LLMs](https://scripts.nuxt.com/docs/api/use-script-trigger-idle-timeout.md)

[**useScriptTriggerElement()** Load a script in response to an element event or visibility change.](https://scripts.nuxt.com/docs/api/use-script-trigger-element) [**useScriptTriggerInteraction()** Load a script after a configured user interaction.](https://scripts.nuxt.com/docs/api/use-script-trigger-interaction)

**On this page **

- [Signature](#signature)
- [Arguments](#arguments)
- [Returns](#returns)
- [Nuxt Config Usage](#nuxt-config-usage)
- [Examples](#examples)
- [Choosing a Timeout](#choosing-a-timeout)

```json
{"@context":"https://schema.org","@graph":[{"@id":"https://scripts.nuxt.com/#website","@type":"WebSite","description":"Nuxt Scripts lets you load third-party scripts with better performance, privacy, security and DX. It includes many popular third-parties out of the box.","name":"Nuxt Scripts","url":"https://scripts.nuxt.com/","publisher":{"@id":"https://scripts.nuxt.com/#identity"}},{"@id":"https://scripts.nuxt.com/docs/api/use-script-trigger-idle-timeout#webpage","@type":"WebPage","description":"Load a script after Nuxt is ready and an idle timeout has elapsed.","name":"useScriptTriggerIdleTimeout()","url":"https://scripts.nuxt.com/docs/api/use-script-trigger-idle-timeout","breadcrumb":{"@id":"https://scripts.nuxt.com/docs/api/use-script-trigger-idle-timeout#breadcrumb"},"isPartOf":{"@id":"https://scripts.nuxt.com/#website"},"potentialAction":[{"@type":"ReadAction","target":["https://scripts.nuxt.com/docs/api/use-script-trigger-idle-timeout"]}],"primaryImageOfPage":{"@id":"https://scripts.nuxt.com/#logo"}},{"@id":"https://scripts.nuxt.com/#identity","@type":"Organization","name":"Nuxt Scripts","url":"https://scripts.nuxt.com","logo":{"@id":"https://scripts.nuxt.com/#logo"}},{"@id":"https://scripts.nuxt.com/docs/api/use-script-trigger-idle-timeout#breadcrumb","@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","name":"Nuxt Scripts","item":"https://scripts.nuxt.com/","position":1},{"@type":"ListItem","name":"Documentation","item":"https://scripts.nuxt.com/docs","position":2},{"@type":"ListItem","name":"API","item":"https://scripts.nuxt.com/docs/api","position":3},{"@type":"ListItem","name":"useScriptTriggerIdleTimeout()","item":"https://scripts.nuxt.com/docs/api/use-script-trigger-idle-timeout","position":4}]},{"@id":"https://scripts.nuxt.com/#logo","@type":"ImageObject","caption":"Nuxt Scripts","contentUrl":"https://scripts.nuxt.com/logo.svg","inLanguage":"en","url":"https://scripts.nuxt.com/logo.svg"}]}
```

## Sitemap

See the full [sitemap](https://scripts.nuxt.com/sitemap.md) for all pages.
