1

I have a nuxt2-webapp with a lot of routes and for all routes except 2, I need a script to be injected. Is there a way to disable the injecting?

Nuxt config:

meta: [
  script: [
    {
      id: 'Cookiebot',
      src: 'https://consent.cookiebot.com/uc.js',
      'data-cbid': 'xxxxx',
      type: 'text/javascript',
      async: true,
    },
  ],
]
0

2 Answers 2

1

No, there is no way to do so.
If you inject a script, it will be on the window object. Hence available everywhere in your DOM.

What's the issue with that? You could hide your thing with some CSS if it's annoying visually.

Sign up to request clarification or add additional context in comments.

6 Comments

ah snap... The issue is that we want certain pages to be embed-able without any third-party scripts or cookies and cookiebot for example is setting those. (also its kinda a performance-topic, because we want to the pages to be blazing fast and therefor we need the page to be as slim as possible
Oh, you want to have an iframe of your website put into another one? But without the cookie on this specific path? AFAIK, cookies are domain specific and not path specific so I you have some of them somewhere in your website, it's basically all of them everywhere @PeterHauer
yeah exactly. The embedded pages are completely independent of cookies and if you embed a website on your own website you need to include their cookies in your cookie-declaration which is not that nice when you want to sell your embeds.
This could maybe be solved with some nice and smooth CSS. It's always annoying anyway yeah. Maybe just create something totally separate for those 2 page embeds? @PeterHauer
haha seperating those pages would be the next step :D thx for your help!
|
0

The best way to achieve this behaviour is via a plugin:

export default (context: Context) => {
  if (!context.route.name?.includes('embed')) {
    const scriptTag = document.createElement('script');
    scriptTag.id = 'Cookiebot';
    scriptTag.src = 'https://consent.cookiebot.com/uc.js';
    scriptTag.setAttribute('data-cbid', 'xxxx');
    scriptTag.type = 'text/javascript';
    scriptTag.async = true;
    document.head.appendChild(scriptTag);
  }
};

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.