Web Worker Offloading

설명

This plugin offloads JavaScript execution to a Web Worker, improving performance by freeing up the main thread. This should translate into improved Interaction to Next Paint (INP) scores.

This functionality is experimental.

In order to opt in a script to be loaded in a worker, simply add worker script data to a registered script. For example,
if you have a script registered with the handle of foo, opt-in to offload it to a web worker by doing:

wp_script_add_data( 'foo', 'worker', true );

Unlike with the script loading strategies (async/defer), any inline before/after scripts associated with the worker-offloaded registered script will also be offloaded to the worker, whereas with the script strategies an inline after script would block the script from being delayed.

Otherwise, the plugin currently ships with built-in integrations to offload Google Analytics to a web worker for the following plugin:

Please monitor your analytics once activating to ensure all the expected events are being logged. At the same time, monitor your INP scores to check for improvement.

This plugin relies on the Partytown 🎉 library by Builder.io, released under the MIT license. This library is in beta and there are quite a few open bugs.

The Partytown configuration can be modified via the plwwo_configuration filter. For example:

<?php
add_filter( 'plwwo_configuration', function ( $config ) {
    $config['mainWindowAccessors'][] = 'wp'; // Make the wp global available in the worker (e.g. wp.i18n and wp.hooks).
    return $config;
} );

However, not all of the configuration options can be serialized to JSON in this way, for example the resolveUrl configuration is a function. To specify this, you can add an inline script as follows.

<?php
add_action(
    'wp_enqueue_scripts',
    function () {
        wp_add_inline_script(
            'web-worker-offloading',
            <<<JS
            window.partytown = {
                ...(window.partytown || {}),
                resolveUrl: (url, location, type) => {
                    if (type === 'script') {
                        const proxyUrl = new URL('https://my-reverse-proxy.example.com/');
                        proxyUrl.searchParams.append('url', url.href);
                        return proxyUrl;
                    }
                    return url;
                },
            };
            JS,
            'before'
        );
    }
);

There are also many configuration options which are not documented, so refer to the TypeScript definitions.

FAQ

Why are my offloaded scripts not working and I see a 404 error in the console for `partytown-sandbox-sw.html`?

If you find that your offloaded scripts aren’t working while also seeing a 404 error in the console for a file at /wp-content/plugins/web-worker-offloading/build/partytown-sandbox-sw.html?1727389399791 then it’s likely you have Chrome DevTools open with the “Bypass for Network” toggle enabled in the Application panel.

Where can I report security bugs?

The Performance team and WordPress community take security bugs seriously. We appreciate your efforts to responsibly disclose your findings, and will make every effort to acknowledge your contributions.

To report a security issue, please visit the WordPress HackerOne program.

How can I contribute to the plugin?

Contributions are always welcome! Learn more about how to get involved in the Core Performance Team Handbook.

The plugin source code is located in the WordPress/performance repo on GitHub.

후기

2025년 1월 12일 답글 1개
Problems with Google Analytics and Google Tag ManagerTested: 1 week. While Enabled: No hits, no recorded live users/users in Google Analytics. Google Tag Manager also didnt get to connect to the site. – Clarity did record users live, and page hits. This is because Clarity is not included in the built-in integrationWhile disabled: Google Analytics got hits right away – same with Google Tag Manager.
모든 1 평가 읽기

기여자 & 개발자

“Web Worker Offloading”(은)는 오픈 소스 소프트웨어입니다. 다음의 사람들이 이 플러그인에 기여하였습니다.

기여자

“Web Worker Offloading”(이)가 5 개 언어로 번역되었습니다. 기여해 주셔서 번역자님께 감사드립니다.

자국어로 “Web Worker Offloading”(을)를 번역하세요.

개발에 관심이 있으십니까?

코드 탐색하기는, SVN 저장소를 확인하시거나, 개발 기록RSS로 구독하세요.

변경이력

0.2.0

Enhancements

  • Integrate Web Worker Offloading with Google Site Kit. (1686)
  • Integrate Web Worker Offloading with Rank Math SEO. (1685)
  • Serve unminified scripts when SCRIPT_DEBUG is enabled. (1643)

Bug Fixes

  • Fix tracking events like add_to_cart in WooCommerce integration. (1740)

0.1.1

Enhancements

  • Add Web Worker Offloading meta generator. (1598)

0.1.0

  • Initial release.