Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support manual script deduping #148

Merged
merged 1 commit into from
Jul 13, 2024
Merged

Conversation

harlan-zw
Copy link
Collaborator

Fixes #97

πŸ”— Linked issue

❓ Type of change

  • πŸ“– Documentation (updates to the documentation or readme)
  • 🐞 Bug fix (a non-breaking change that fixes an issue)
  • πŸ‘Œ Enhancement (improving an existing functionality)
  • ✨ New feature (a non-breaking change that adds functionality)
  • 🧹 Chore (updates to the build process or auxiliary tools and libraries)
  • ⚠️ Breaking change (fix or feature that would cause existing functionality to change)

πŸ“š Description

Loading multiple of the same script

You may have a setup where you need to load the same registry script multiple times
using different configuration.

By default, they will be deduped and only loaded once, to load multiple instances of the same script, you can provide a unique key to the script.

const { gtag, $script } = useScriptGoogleAnalytics({
  id: 'G-TR58L0EF8P',
})

const { gtag: gtag2, $script: $script2 } = useScriptGoogleAnalytics({
  // without a key the first script instance will be returned
  key: 'gtag2',
  id: 'G-1234567890',
})

It's important to note that when modifying the key, any environment variables you're using will break.

For example, with gtag2 as the key, you'd need to provide runtime config as following:

export default defineNuxtConfig({
  runtimeConfig: {
    public: {
      scripts: {
        gtag2: {
          id: '', // NUXT_PUBLIC_SCRIPTS_GTAG2_ID
        },
      },
    },
  },
})

Copy link

vercel bot commented Jul 13, 2024

The latest updates on your projects. Learn more about Vercel for Git β†—οΈŽ

Name Status Preview Comments Updated (UTC)
scripts-docs πŸ”„ Building (Inspect) Visit Preview πŸ’¬ Add feedback Jul 13, 2024 8:34am
scripts-playground βœ… Ready (Inspect) Visit Preview πŸ’¬ Add feedback Jul 13, 2024 8:34am

@harlan-zw harlan-zw merged commit 253085d into main Jul 13, 2024
3 of 4 checks passed
@harlan-zw harlan-zw deleted the feat/manual-script-deduping branch July 13, 2024 08:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support / document how to use multiple of the same script
1 participant