Script Loader: Improve performance of wp_maybe_inline_styles function.
The `wp_maybe_inline_styles` function is called twice on the average page load. On it's second run however, it did not check to see if the style had already been processed on the first run. This resulted in calling `filesize` and `get_file_contents` unnecessarily, which was bad for performance. Now, the loop around the queued styles, checks to see if the source is set to false, meaning it has already been processed. This change also replaces calls to `filesize` with the core function `wp_filesize`, which improves extensibility. Props spacedmonkey, flixos90, peterwilsoncc, joemcgill. Fixes #58394. Built from https://develop.svn.wordpress.org/trunk@55888 git-svn-id: http://core.svn.wordpress.org/trunk@55400 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
b62f326588
commit
abee3f00a1
|
@ -2872,12 +2872,18 @@ function wp_maybe_inline_styles() {
|
|||
|
||||
// Build an array of styles that have a path defined.
|
||||
foreach ( $wp_styles->queue as $handle ) {
|
||||
if ( wp_styles()->get_data( $handle, 'path' ) && file_exists( $wp_styles->registered[ $handle ]->extra['path'] ) ) {
|
||||
$src = $wp_styles->registered[ $handle ]->src;
|
||||
$path = wp_styles()->get_data( $handle, 'path' );
|
||||
if ( $path && $src ) {
|
||||
$size = wp_filesize( $path );
|
||||
if ( ! $size ) {
|
||||
continue;
|
||||
}
|
||||
$styles[] = array(
|
||||
'handle' => $handle,
|
||||
'src' => $wp_styles->registered[ $handle ]->src,
|
||||
'path' => $wp_styles->registered[ $handle ]->extra['path'],
|
||||
'size' => filesize( $wp_styles->registered[ $handle ]->extra['path'] ),
|
||||
'src' => $src,
|
||||
'path' => $path,
|
||||
'size' => $size,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
*
|
||||
* @global string $wp_version
|
||||
*/
|
||||
$wp_version = '6.3-alpha-55887';
|
||||
$wp_version = '6.3-alpha-55888';
|
||||
|
||||
/**
|
||||
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.
|
||||
|
|
Loading…
Reference in New Issue