Skip to content

Commit

Permalink
fix: Unhead 1.9 integration
Browse files Browse the repository at this point in the history
  • Loading branch information
harlan-zw committed Mar 25, 2024
1 parent 24725e4 commit 720f6e3
Show file tree
Hide file tree
Showing 4 changed files with 457 additions and 575 deletions.
10 changes: 4 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,19 @@ Better Privacy, Performance, and DX for Third-Party Scripts in Nuxt Apps.

All the features from Unhead [useScript](https://unhead.unjs.io/usage/composables/use-script):

- 🦥 Lazy, but fast: `defer`, `fetchpriority: 'low'`, early connections (`preconnect`, `dns-prefetch`)
- ☕ Loading strategies: `idle`, `manual`, `Promise`
- ☕ Loading strategies: `manual`, `Promise`
- 🪨 Single script instance for your app
- 🎃 Events for SSR scripts: `onload`, `onerror`, etc
- 🪝 Proxy API: call the script functions before it's loaded, noop for SSR, stubbable, etc
- 🇹 Fully typed APIs

Plus Nuxt goodies:

- 🦥 `onNuxtReady` Loading strategy
- ⏬ Serve third-party scripts from your own server
- 🕵️ Privacy Features - Trigger scripts loading on consent.
- 🪵 DevTools integration - View your script with their status and see function logs
- (TODO) Automatic Early connections (`preconnect`, `dns-prefetch`)

## Background

Expand Down Expand Up @@ -107,9 +108,7 @@ Nuxt Scripts provides a `createScriptConsentTrigger` composable that allows you
You can either use it by providing a resolvable consent (ref, promise) option or by using `accept()`.

```ts
export const agreedToCookiesScriptConsent = createScriptConsentTrigger({
honourDoNotTrack: true,
})
export const agreedToCookiesScriptConsent = createScriptConsentTrigger()
// ...
useScript('https://www.google-analytics.com/analytics.js', {
trigger: agreedToCookiesScriptConsent
Expand All @@ -123,7 +122,6 @@ const agreedToCookies = ref(false)
useScript('https://www.google-analytics.com/analytics.js', {
// will be loaded in when the ref is true
trigger: createScriptConsentTrigger({
honourDoNotTrack: true, // optional, disabled by default
consent: agreedToCookies
})
})
Expand Down
Loading

0 comments on commit 720f6e3

Please sign in to comment.