| 1 |
<?php |
| 2 |
/** |
| 3 |
* Plugin Name: Web Worker Offloading |
| 4 |
* Plugin URI: https://github.com/WordPress/performance/issues/176 |
| 5 |
* Description: Offloads select JavaScript execution to a Web Worker to reduce work on the main thread and improve the Interaction to Next Paint (INP) metric. |
| 6 |
* Requires at least: 6.9 |
| 7 |
* Requires PHP: 7.4 |
| 8 |
* Version: 0.3.0 |
| 9 |
* Author: WordPress Performance Team |
| 10 |
* Author URI: https://make.wordpress.org/performance/ |
| 11 |
* License: GPLv2 or later |
| 12 |
* License URI: https://www.gnu.org/licenses/old-licenses/gpl-2.0.html |
| 13 |
* Text Domain: web-worker-offloading |
| 14 |
* |
| 15 |
* @package web-worker-offloading |
| 16 |
*/ |
| 17 |
|
| 18 |
declare( strict_types = 1 ); |
| 19 |
|
| 20 |
// @codeCoverageIgnoreStart |
| 21 |
if ( ! defined( 'ABSPATH' ) ) { |
| 22 |
exit; // Exit if accessed directly. |
| 23 |
} |
| 24 |
|
| 25 |
// Define the constant. |
| 26 |
if ( defined( 'WEB_WORKER_OFFLOADING_VERSION' ) ) { |
| 27 |
return; |
| 28 |
} |
| 29 |
|
| 30 |
if ( |
| 31 |
( is_admin() || ( defined( 'WP_CLI' ) && WP_CLI ) ) && |
| 32 |
! file_exists( __DIR__ . '/build/partytown.asset.php' ) |
| 33 |
) { |
| 34 |
// phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_trigger_error |
| 35 |
trigger_error( |
| 36 |
esc_html( |
| 37 |
sprintf( |
| 38 |
/* translators: 1: File path. 2: CLI command. */ |
| 39 |
'[Web Worker Offloading] ' . __( 'Unable to load %1$s. Please make sure you have run %2$s.', 'web-worker-offloading' ), |
| 40 |
'build/partytown.asset.php', |
| 41 |
'`npm install && npm run build:plugin:web-worker-offloading`' |
| 42 |
) |
| 43 |
), |
| 44 |
E_USER_ERROR |
| 45 |
); |
| 46 |
} |
| 47 |
|
| 48 |
define( 'WEB_WORKER_OFFLOADING_VERSION', '0.3.0' ); |
| 49 |
|
| 50 |
require_once __DIR__ . '/helper.php'; |
| 51 |
require_once __DIR__ . '/hooks.php'; |
| 52 |
require_once __DIR__ . '/third-party.php'; |
| 53 |
// @codeCoverageIgnoreEnd |
| 54 |
|