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

use this library for 3rd party scripts #2

Open
andresclua opened this issue Jan 20, 2024 · 0 comments
Open

use this library for 3rd party scripts #2

andresclua opened this issue Jan 20, 2024 · 0 comments

Comments

@andresclua
Copy link

andresclua commented Jan 20, 2024

hey - found this after 20 in search, and is not an issue, is more a question... could this library be used to load 3rd party scripts as google tag manager or analytics? I know that SW cannot access to the page, but I'm not an expert on this item.

I'm thinking something like...

html

<body>

      <!-- Example of custom type script -->
      <script type="type/multithreading">
        console.log('Script 1 is running.');
        // Additional JavaScript code for Script 1...
    </script>

    <script type="type/multithreading">
        console.log('Script 2 is running.');
        // Additional JavaScript code for Script 2...
    </script>

    <!-- Standard script to execute custom type scripts -->
   
    <div id="app"></div>
    <script type="module" src="/main.js"></script>

  </body>

js

import { threaded } from "multithreading";

const add = threaded(function* (a, b){
    document.querySelectorAll('script[type="type/multithreading"]').forEach(script => {
      try {
          new Function(script.innerText)();
      } catch (e) {
          console.error('Error executing multithreading script:', e);
      }
  });
});
await add()
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

No branches or pull requests

1 participant