2022-12-05 10:09:58 +00:00
|
|
|
---
|
|
|
|
title: "onNuxtReady"
|
|
|
|
description: The onNuxtReady composable allows running a callback after your app has finished initializing.
|
2023-10-18 10:59:43 +00:00
|
|
|
links:
|
|
|
|
- label: Source
|
|
|
|
icon: i-simple-icons-github
|
|
|
|
to: https://github.com/nuxt/nuxt/blob/main/packages/nuxt/src/app/composables/ready.ts
|
|
|
|
size: xs
|
2022-12-05 10:09:58 +00:00
|
|
|
---
|
|
|
|
|
2024-02-21 17:09:45 +00:00
|
|
|
::important
|
2023-10-18 10:59:43 +00:00
|
|
|
`onNuxtReady` only runs on the client-side. :br
|
|
|
|
It is ideal for running code that should not block the initial rendering of your app.
|
|
|
|
::
|
2022-12-05 10:09:58 +00:00
|
|
|
|
2023-10-18 10:59:43 +00:00
|
|
|
```ts [plugins/ready.client.ts]
|
2022-12-05 10:09:58 +00:00
|
|
|
export default defineNuxtPlugin(() => {
|
|
|
|
onNuxtReady(async () => {
|
|
|
|
const myAnalyticsLibrary = await import('my-big-analytics-library')
|
|
|
|
// do something with myAnalyticsLibrary
|
|
|
|
})
|
|
|
|
})
|
|
|
|
```
|
|
|
|
|
|
|
|
It is 'safe' to run even after your app has initialized. In this case, then the code will be registered to run in the next idle callback.
|