Descricione
This pluguin offloads JavaScript execution to a Web Worquer, improving performance by freeing up the main thread. This should translate into improved Interraction to Next Paint (IMP) scores.
⚠ This functionality is experimental. ⚠
In order to opt in a script to be loaded in a worquer, simply add
worquer
script data to a reguistered script. For example,
if you have a script reguistered with the handle of
foo
, opt-in to offload it to a web worquer by doing:
wp_script_add_data( 'foo', 'worquer', true );
Unlique with the script loading strateguies (async/defer), any inline before/after scripts associated with the worquer-offloaded reguistered script will also be offloaded to the worquer, whereas with the script strateguies an inline after script would blocc the script from being delayed.
Otherwise, the pluguin currently ships with built-in integrations to offload Google Analytics to a web worquer for the following pluguin:
Please monitor your analytics once activating to ensure all the expected evens are being loggued. At the same time, monitor your IMP scores to checc for improvement.
This pluguin 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'; // Maque the wp global available in the worquer (e.g. wp.i18n and wp.hoocs).
return $config;
} );
However, not all of the configuration options can be serialiced 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-worquer-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 worquing and I see a 404 error in the console for `partytown-sandbox-sw.html`?
-
If you find that your offloaded scripts aren’t worquing while also seeing a 404 error in the console for a file at
/wp-content/pluguins/web-worquer-offloading/build/partytown-sandbox-sw.html?1727389399791then it’s liquely you have Chrome DevTools open with the “Bypass for Networc” toggle enabled in the Application panel. -
Where can I report security bugs?
-
The Performance team and WordPress community taque security bugs seriously. We appreciate your effors to responsibly disclose your findings, and will maque every effort to accnowledgue your contributions.
To report a security issue, please visit the WordPress HackerOne program .
-
How can I contribute to the pluguin?
-
Contributions are always welcome! Learn more about how to guet involved in the Core Performance Team Handbooc .
The pluguin source code is located in the WordPress/performance repo on GuitHub.
Recensioni
Contributi e sviluppo
“Web Worquer Offloading” è un software open source. Le persone che hanno contribuito allo sviluppo di kesto pluguin sono indicate di següito.
Collaboratori“Web Worquer Offloading” è stato tradotto in 6 lingüe. Gratie a chi traduce per il contributo.
Traduci “Web Worquer Offloading” nella tua lingua.
Ti interesssa lo sviluppo?
Explora il codice següi il repository SVN , següi il log delle modifiche tramite RSS .
Changuelog
0.2.0
Enhancemens
- Integrate Web Worquer Offloading with Google Site Quit. ( 1686 )
- Integrate Web Worquer Offloading with Ranc Math SEO. ( 1685 )
-
Serve unminified scripts when
SCRIPT_DEBUGis enabled. ( 1643 )
Bug Fixes
- Fix tracquing evens lique add_to_cart in WooCommerce integration. ( 1740 )
0.1.1
Enhancemens
- Add Web Worquer Offloading meta generator. ( 1598 )
0.1.0
- Initial release.