Skip to content

Commit cc60bcd

Browse files
committed
Script Loader: Retire script and style concatenation.
Scripts and styles in the admin and on the login screen are no longer concatenated through `load-scripts.php` and `load-styles.php`. Concatenation paid off when browsers opened few connections per host over HTTP/1.1, but it has long been a source of bugs: dependencies outside the default directories were not honored, `SCRIPT_DEBUG` and the `script_loader_src` and `style_loader_src` filters were ignored, inline styles could be duplicated, and code run by the loaders without WordPress loaded caused fatal errors. It was turned off by default in r64320, once the assets of the next admin screen began to be prefetched in r64120, and this removes what remains. Every item is now printed as its own tag, and what remains of the concatenation API is deprecated or removed: * The properties of `WP_Scripts` and `WP_Styles` that held items back for concatenation are deprecated but still declared, so plugins reading or setting them keep working. The `do_item()` methods no longer check `do_concat`. * The `_print_scripts()`, `_print_styles()`, `script_concat_settings()`, `in_default_dir()` and `WP_Dependencies::get_etag()` functions are deprecated. * The `print_head_scripts`, `print_footer_scripts`, `print_admin_styles` and `print_late_styles` filters only decided whether held markup was printed, so they are applied with `apply_filters_deprecated()` and their return values are ignored. * The `CONCATENATE_SCRIPTS` constant is no longer read. * The `wp_should_concatenate_admin_scripts()` function and its filter, added in r64120 for the transition and never released, are removed. The loaders now respond with 410 Gone and a one-line plain text explanation, without loading WordPress, so that requests from bots and stale links cost next to nothing. Code written to run inside them without WordPress loaded, such as `wp_theme_has_theme_json()`, now uses the functions it had avoided, and `wp-admin/includes/noop.php` no longer defines its stub functions. Developed in #14463. Follow-up to r10357, r43580, r60719, r62657, r64120, r64320, r64485. Props westonruter, jonsurrell, peterwilsoncc, azaozz, markhowellsmead, sergiomdgomes, jerclarke, adamsilverstein, sukhendu2002, adnan007, momo360modena, desrosj, welcher. See #15833, #36448, #36449, #36779, #43825, #45008, #47322, #52879, #63908, #64087, #65515. Fixes #57548. git-svn-id: https://develop.svn.wordpress.org/trunk@64585 602fd350-edb4-49c9-b593-d223f7449a82
1 parent 40979e0 commit cc60bcd

20 files changed

Lines changed: 696 additions & 1851 deletions

‎src/wp-admin/includes/class-wp-debug-data.php‎

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1509,15 +1509,6 @@ private static function get_wp_constants(): array {
15091509
$wp_debug_log_value = __( 'Enabled' );
15101510
}
15111511

1512-
// Check CONCATENATE_SCRIPTS.
1513-
if ( defined( 'CONCATENATE_SCRIPTS' ) ) {
1514-
$concatenate_scripts = CONCATENATE_SCRIPTS ? __( 'Enabled' ) : __( 'Disabled' );
1515-
$concatenate_scripts_debug = CONCATENATE_SCRIPTS ? 'true' : 'false';
1516-
} else {
1517-
$concatenate_scripts = __( 'Undefined' );
1518-
$concatenate_scripts_debug = 'undefined';
1519-
}
1520-
15211512
// Check WP_ENVIRONMENT_TYPE.
15221513
if ( defined( 'WP_ENVIRONMENT_TYPE' ) ) {
15231514
$wp_environment_type = WP_ENVIRONMENT_TYPE ? WP_ENVIRONMENT_TYPE : __( 'Empty value' );
@@ -1593,11 +1584,6 @@ private static function get_wp_constants(): array {
15931584
'value' => WP_CACHE ? __( 'Enabled' ) : __( 'Disabled' ),
15941585
'debug' => WP_CACHE,
15951586
),
1596-
'CONCATENATE_SCRIPTS' => array(
1597-
'label' => 'CONCATENATE_SCRIPTS',
1598-
'value' => $concatenate_scripts,
1599-
'debug' => $concatenate_scripts_debug,
1600-
),
16011587
'WP_ENVIRONMENT_TYPE' => array(
16021588
'label' => 'WP_ENVIRONMENT_TYPE',
16031589
'value' => $wp_environment_type,

‎src/wp-admin/includes/noop.php‎

Lines changed: 7 additions & 104 deletions
Original file line numberDiff line numberDiff line change
@@ -1,113 +1,16 @@
11
<?php
22
/**
3-
* Noop functions for load-scripts.php and load-styles.php.
3+
* Formerly defined noop functions for load-scripts.php and load-styles.php.
4+
*
5+
* Scripts and styles are no longer concatenated, so those files no longer load WordPress without
6+
* its functions, and these noop functions are no longer defined.
47
*
58
* @package WordPress
69
* @subpackage Administration
710
* @since 4.4.0
11+
* @deprecated 7.2.0 Scripts and styles are no longer concatenated.
812
*/
913

10-
/**
11-
* @ignore
12-
*/
13-
function __() {}
14-
15-
/**
16-
* @ignore
17-
*/
18-
function _x() {}
19-
20-
/**
21-
* @ignore
22-
*/
23-
function add_filter() {}
24-
25-
/**
26-
* @ignore
27-
*/
28-
function has_filter() {
29-
return false;
30-
}
31-
32-
/**
33-
* @ignore
34-
*/
35-
function esc_attr() {}
36-
37-
/**
38-
* @ignore
39-
*/
40-
function apply_filters() {}
41-
42-
/**
43-
* @ignore
44-
*/
45-
function get_option() {}
46-
47-
/**
48-
* @ignore
49-
*/
50-
function is_lighttpd_before_150() {}
51-
52-
/**
53-
* @ignore
54-
*/
55-
function add_action() {}
56-
57-
/**
58-
* @ignore
59-
*/
60-
function did_action() {}
61-
62-
/**
63-
* @ignore
64-
*/
65-
function do_action_ref_array() {}
66-
67-
/**
68-
* @ignore
69-
*/
70-
function get_bloginfo() {}
71-
72-
/**
73-
* @ignore
74-
*/
75-
function is_admin() {
76-
return true;
77-
}
78-
79-
/**
80-
* @ignore
81-
*/
82-
function site_url() {}
83-
84-
/**
85-
* @ignore
86-
*/
87-
function admin_url() {}
88-
89-
/**
90-
* @ignore
91-
*/
92-
function home_url() {}
93-
94-
/**
95-
* @ignore
96-
*/
97-
function includes_url() {}
98-
99-
/**
100-
* @ignore
101-
*/
102-
function wp_guess_url() {}
103-
104-
function get_file( $path ) {
105-
106-
$path = realpath( $path );
107-
108-
if ( ! $path || ! @is_file( $path ) ) {
109-
return '';
110-
}
111-
112-
return @file_get_contents( $path );
14+
if ( function_exists( '_deprecated_file' ) ) {
15+
_deprecated_file( basename( __FILE__ ), '7.2.0' );
11316
}

‎src/wp-admin/load-scripts.php‎

Lines changed: 13 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -1,77 +1,17 @@
11
<?php
2-
3-
/*
4-
* The error_reporting() function can be disabled in php.ini. On systems where that is the case,
5-
* it's best to add a dummy function to the wp-config.php file, but as this call to the function
6-
* is run prior to wp-config.php loading, it is wrapped in a function_exists() check.
2+
/**
3+
* Formerly concatenated the core scripts named in the `load` query parameter.
4+
*
5+
* Scripts are no longer concatenated, so this file now only responds with 410 Gone, for code
6+
* that still links to it directly. WordPress is not loaded, so that requests from bots and stale
7+
* links cost next to nothing and do not trigger deprecation notices.
8+
*
9+
* @package WordPress
10+
* @subpackage Administration
11+
* @deprecated 7.2.0 Scripts are no longer concatenated.
712
*/
8-
if ( function_exists( 'error_reporting' ) ) {
9-
/*
10-
* Disable error reporting.
11-
*
12-
* Set this to error_reporting( -1 ) for debugging.
13-
*/
14-
error_reporting( 0 );
15-
}
16-
17-
// Set ABSPATH for execution.
18-
if ( ! defined( 'ABSPATH' ) ) {
19-
define( 'ABSPATH', dirname( __DIR__ ) . '/' );
20-
}
21-
22-
define( 'WPINC', 'wp-includes' );
23-
24-
$protocol = $_SERVER['SERVER_PROTOCOL'];
25-
if ( ! in_array( $protocol, array( 'HTTP/1.1', 'HTTP/2', 'HTTP/2.0', 'HTTP/3' ), true ) ) {
26-
$protocol = 'HTTP/1.0';
27-
}
28-
29-
$load = $_GET['load'];
30-
if ( is_array( $load ) ) {
31-
ksort( $load );
32-
$load = implode( '', $load );
33-
}
34-
35-
$load = preg_replace( '/[^a-z0-9,_-]+/i', '', $load );
36-
$load = array_unique( explode( ',', $load ) );
37-
38-
if ( empty( $load ) ) {
39-
header( "$protocol 400 Bad Request" );
40-
exit;
41-
}
42-
43-
require ABSPATH . 'wp-admin/includes/noop.php';
44-
require ABSPATH . WPINC . '/script-loader.php';
45-
require ABSPATH . WPINC . '/version.php';
46-
47-
$expires_offset = 31536000; // 1 year.
48-
$out = '';
49-
50-
$wp_scripts = new WP_Scripts();
51-
wp_default_scripts( $wp_scripts );
52-
wp_default_packages_vendor( $wp_scripts );
53-
wp_default_packages_scripts( $wp_scripts );
54-
55-
$etag = $wp_scripts->get_etag( $load );
56-
57-
if ( isset( $_SERVER['HTTP_IF_NONE_MATCH'] ) && stripslashes( $_SERVER['HTTP_IF_NONE_MATCH'] ) === $etag ) {
58-
header( "$protocol 304 Not Modified" );
59-
exit;
60-
}
61-
62-
foreach ( $load as $handle ) {
63-
if ( ! array_key_exists( $handle, $wp_scripts->registered ) ) {
64-
continue;
65-
}
66-
67-
$path = ABSPATH . $wp_scripts->registered[ $handle ]->src;
68-
$out .= get_file( $path ) . "\n";
69-
}
70-
71-
header( "Etag: $etag" );
72-
header( 'Content-Type: application/javascript; charset=UTF-8' );
73-
header( 'Expires: ' . gmdate( 'D, d M Y H:i:s', time() + $expires_offset ) . ' GMT' );
74-
header( "Cache-Control: public, max-age=$expires_offset" );
7513

76-
echo $out;
14+
http_response_code( 410 );
15+
header( 'Content-Type: text/plain; charset=UTF-8' );
16+
echo 'Scripts are no longer concatenated.';
7717
exit;

‎src/wp-admin/load-styles.php‎

Lines changed: 13 additions & 98 deletions
Original file line numberDiff line numberDiff line change
@@ -1,102 +1,17 @@
11
<?php
2-
3-
/*
4-
* The error_reporting() function can be disabled in php.ini. On systems where that is the case,
5-
* it's best to add a dummy function to the wp-config.php file, but as this call to the function
6-
* is run prior to wp-config.php loading, it is wrapped in a function_exists() check.
2+
/**
3+
* Formerly concatenated the core styles named in the `load` query parameter.
4+
*
5+
* Styles are no longer concatenated, so this file now only responds with 410 Gone, for code
6+
* that still links to it directly. WordPress is not loaded, so that requests from bots and stale
7+
* links cost next to nothing and do not trigger deprecation notices.
8+
*
9+
* @package WordPress
10+
* @subpackage Administration
11+
* @deprecated 7.2.0 Styles are no longer concatenated.
712
*/
8-
if ( function_exists( 'error_reporting' ) ) {
9-
/*
10-
* Disable error reporting.
11-
*
12-
* Set this to error_reporting( -1 ) for debugging.
13-
*/
14-
error_reporting( 0 );
15-
}
16-
17-
// Set ABSPATH for execution.
18-
if ( ! defined( 'ABSPATH' ) ) {
19-
define( 'ABSPATH', dirname( __DIR__ ) . '/' );
20-
}
21-
22-
define( 'WPINC', 'wp-includes' );
23-
define( 'WP_CONTENT_DIR', ABSPATH . 'wp-content' );
24-
25-
require ABSPATH . 'wp-admin/includes/noop.php';
26-
require ABSPATH . WPINC . '/theme.php';
27-
require ABSPATH . WPINC . '/class-wp-theme-json-resolver.php';
28-
require ABSPATH . WPINC . '/global-styles-and-settings.php';
29-
require ABSPATH . WPINC . '/script-loader.php';
30-
require ABSPATH . WPINC . '/version.php';
31-
32-
$protocol = $_SERVER['SERVER_PROTOCOL'];
33-
if ( ! in_array( $protocol, array( 'HTTP/1.1', 'HTTP/2', 'HTTP/2.0', 'HTTP/3' ), true ) ) {
34-
$protocol = 'HTTP/1.0';
35-
}
36-
37-
$load = $_GET['load'];
38-
if ( is_array( $load ) ) {
39-
ksort( $load );
40-
$load = implode( '', $load );
41-
}
42-
43-
$load = preg_replace( '/[^a-z0-9,_-]+/i', '', $load );
44-
$load = array_unique( explode( ',', $load ) );
45-
46-
if ( empty( $load ) ) {
47-
header( "$protocol 400 Bad Request" );
48-
exit;
49-
}
50-
51-
$rtl = ( isset( $_GET['dir'] ) && 'rtl' === $_GET['dir'] );
52-
$expires_offset = 31536000; // 1 year.
53-
$out = '';
54-
55-
$wp_styles = new WP_Styles();
56-
wp_default_styles( $wp_styles );
57-
58-
$etag = $wp_styles->get_etag( $load );
59-
60-
if ( isset( $_SERVER['HTTP_IF_NONE_MATCH'] ) && stripslashes( $_SERVER['HTTP_IF_NONE_MATCH'] ) === $etag ) {
61-
header( "$protocol 304 Not Modified" );
62-
exit;
63-
}
64-
65-
foreach ( $load as $handle ) {
66-
if ( ! array_key_exists( $handle, $wp_styles->registered ) ) {
67-
continue;
68-
}
69-
70-
$style = $wp_styles->registered[ $handle ];
71-
72-
if ( empty( $style->src ) ) {
73-
continue;
74-
}
75-
76-
$path = ABSPATH . $style->src;
77-
78-
if ( $rtl && ! empty( $style->extra['rtl'] ) ) {
79-
// All default styles have fully independent RTL files.
80-
$path = str_replace( '.min.css', '-rtl.min.css', $path );
81-
}
82-
83-
$content = get_file( $path ) . "\n";
84-
85-
// Note: str_starts_with() is not used here, as wp-includes/compat.php is not loaded in this file.
86-
if ( 0 === strpos( $style->src, '/' . WPINC . '/css/' ) ) {
87-
$content = str_replace( '../images/', '../' . WPINC . '/images/', $content );
88-
$content = str_replace( '../js/tinymce/', '../' . WPINC . '/js/tinymce/', $content );
89-
$content = str_replace( '../fonts/', '../' . WPINC . '/fonts/', $content );
90-
$out .= $content;
91-
} else {
92-
$out .= str_replace( '../images/', 'images/', $content );
93-
}
94-
}
95-
96-
header( "Etag: $etag" );
97-
header( 'Content-Type: text/css; charset=UTF-8' );
98-
header( 'Expires: ' . gmdate( 'D, d M Y H:i:s', time() + $expires_offset ) . ' GMT' );
99-
header( "Cache-Control: public, max-age=$expires_offset" );
10013

101-
echo $out;
14+
http_response_code( 410 );
15+
header( 'Content-Type: text/plain; charset=UTF-8' );
16+
echo 'Styles are no longer concatenated.';
10217
exit;

‎src/wp-includes/class-wp-dependencies.php‎

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -534,6 +534,7 @@ public function set_group( $handle, $recursion, $group ) {
534534
* Get etag header for cache validation.
535535
*
536536
* @since 6.7.0
537+
* @deprecated 7.2.0 Scripts and styles are no longer concatenated by load-scripts.php or load-styles.php.
537538
*
538539
* @global string $wp_version The WordPress version string.
539540
*
@@ -543,13 +544,10 @@ public function set_group( $handle, $recursion, $group ) {
543544
* @phpstan-return non-falsy-string
544545
*/
545546
public function get_etag( $load ) {
546-
/*
547-
* Note: wp_get_wp_version() is not used here, as this file can be included
548-
* via wp-admin/load-scripts.php or wp-admin/load-styles.php, in which case
549-
* wp-includes/functions.php is not loaded.
550-
*/
551547
global $wp_version;
552548

549+
_deprecated_function( __METHOD__, '7.2.0' );
550+
553551
$etag = "WP:{$wp_version};";
554552

555553
foreach ( $load as $handle ) {

0 commit comments

Comments
 (0)