Configuration

Partytown does not require a config for it to work, however a config can be set to change the defaults. At the lowest level, it’s configured by setting the window.partytown = {...} object before the Partytown snippet script. However, higher-level integrations, such as the <Partytown/> component found in @builder.io/partytown/react, should provide utilities to make setting the config easier

ConfigDescription
debugWhen true, Partytown scripts are not inlined and not minified. See the Debugging docs on how to enable more logging.
forwardAn array of strings representing function calls on the main thread to forward to the web worker. See Forwarding Events and Triggers for more info.
libPath where the Partytown library can be found your server. Note that the path must both start and end with a / character, and the files must be hosted from the same origin as the webpage. Default is /~partytown/
loadScriptsOnMainThreadAn array of strings or regular expressions (RegExp) used to filter out which script are executed via Partytown and the main thread. An example is as follows: loadScriptsOnMainThread: ["https://test.com/analytics.js", "inline-script-id", /regex-matched-script\.js/].
resolveUrlHook that is called to resolve URLs which can be used to modify URLs. The hook uses the API: resolveUrl(url: URL, location: URL, method: string). See the Proxying Requests for more information.
nonceThe nonce property may be set on script elements created by Partytown. This should be set only when dealing with content security policies and when the use of unsafe-inline is disabled (using nonce-* instead).
fallbackTimeoutA timeout in ms until Partytown initialization is considered as failed & fallbacks to the regular execution in main thread. Default is 9999

Vanilla Config

What we mean by “vanilla config”, is that the Partytown config can be set without any higher-level integration. Below is an example of setting the debug config. Notice that the config script tag is before the Partytown snippet script. Additionally, the config or snippet scripts should NOT contain the type="text/partytown" attribute (this small amount of JavaScript we need to run on the main thread to initialize everything).

<html>
  <head>
    <title>Vanilla Config Example</title>
    <script>
      partytown = {
        debug: true,
      };
    </script>
    <script>
      /* Inlined Partytown Snippet */
    </script>
  </head>
  <body>
    ...
  </body>
</html>

Please see the integration guides for more information.

Made with ❤️ by

© 2024 Builder.io, Inc.

Introducing Visual Copilot.

100% free. Supports all popular frameworks.

Try Visual Copilot