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: allow running specific inline scripts on main thread #235

Merged

Conversation

slawekkolodziej
Copy link
Contributor

This PR extends loadScriptsOnMainThread functionality to inline scripts. This modification is required to address a common scenario in which an inline script sets up the environment for another script loaded from the network.

Inline scripts are targeted using the id attribute.

Let's assume that the following snippet is a custom HTML tag in GTM:

<script src="https://third-party-service-that-needs-main-thread.com/tracking.js" async></script>
<script id="third-party-service">
window._thirdParty = window._thirdParty || [];
</script>

Now, using the following configuration:

<Partytown
  loadScriptsOnMainThread={[
    'https://third-party-service-that-needs-main-thread.com/tracking.js',
    'third-party-service'
  ]}
  ...

both scripts will be executed on main thread, but I can still controlled them with GTM from Partytown.


This PR is not enough to run GTM's custom html tag on the main thread. A bug in innerHTML implementation for the HTMLScriptElement should be fixed too. I created a PR with proposed, although not ideal fix #234

@vercel
Copy link

vercel bot commented Aug 2, 2022

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated
partytown ✅ Ready (Inspect) Visit Preview Sep 2, 2022 at 5:00PM (UTC)

@adamdbradley
Copy link
Contributor

Looks great, thanks

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.

None yet

2 participants