From b30b3a4c7d1a2851d394d9b7b25dd384d1169f53 Mon Sep 17 00:00:00 2001 From: Kailey Lampert Date: Wed, 3 Jul 2024 11:02:04 -0700 Subject: [PATCH 1/6] break up asset groups of over 100 --- cssconcat.php | 4 ++++ jsconcat.php | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/cssconcat.php b/cssconcat.php index ea6f6a6..5bcf94d 100644 --- a/cssconcat.php +++ b/cssconcat.php @@ -98,6 +98,10 @@ function do_items( $handles = false, $group = false ) { $stylesheets[ $stylesheet_group_index ] = array(); $stylesheets[ $stylesheet_group_index ][ $media ][ $handle ] = $css_url_parsed['path']; + + if ( count( $stylesheets[ $stylesheet_group_index ][ $media ] ) > 100 ) { + $stylesheet_group_index++; + } $this->done[] = $handle; } else { $stylesheet_group_index++; diff --git a/jsconcat.php b/jsconcat.php index 346a2b8..1757d10 100644 --- a/jsconcat.php +++ b/jsconcat.php @@ -129,6 +129,10 @@ function do_items( $handles = false, $group = false ) { $javascripts[$level]['paths'][] = $js_url_parsed['path']; $javascripts[$level]['handles'][] = $handle; + if ( count( $javascripts[$level]['paths'] ) > 100 ) { + $level++; + } + } else { $level++; $javascripts[$level]['type'] = 'do_item'; From e6d5ea977b82ae60a7752c733ac1ba534848f0db Mon Sep 17 00:00:00 2001 From: Kailey Lampert Date: Thu, 4 Jul 2024 15:41:45 -0700 Subject: [PATCH 2/6] define concat file max as overridable constant --- concat-utils.php | 4 ++++ cssconcat.php | 2 +- jsconcat.php | 2 +- ngx-http-concat.php | 3 +-- 4 files changed, 7 insertions(+), 4 deletions(-) diff --git a/concat-utils.php b/concat-utils.php index 1626331..662e3f3 100644 --- a/concat-utils.php +++ b/concat-utils.php @@ -1,5 +1,9 @@ 100 ) { + if ( count( $stylesheets[ $stylesheet_group_index ][ $media ] ) >= VIP_CONCAT_MAX ) { $stylesheet_group_index++; } $this->done[] = $handle; diff --git a/jsconcat.php b/jsconcat.php index d44bba3..c3af6c8 100644 --- a/jsconcat.php +++ b/jsconcat.php @@ -129,7 +129,7 @@ function do_items( $handles = false, $group = false ) { $javascripts[$level]['paths'][] = $js_url_parsed['path']; $javascripts[$level]['handles'][] = $handle; - if ( count( $javascripts[$level]['paths'] ) > 100 ) { + if ( count( $javascripts[$level]['paths'] ) >= VIP_CONCAT_MAX ) { $level++; } diff --git a/ngx-http-concat.php b/ngx-http-concat.php index 851f06c..97f9499 100644 --- a/ngx-http-concat.php +++ b/ngx-http-concat.php @@ -16,7 +16,6 @@ require_once( __DIR__ . '/concat-utils.php' ); /* Config */ -$concat_max_files = 150; $concat_unique = true; $concat_types = array( 'css' => 'text/css', @@ -114,7 +113,7 @@ function concat_get_path( $uri ) { concat_http_status_exit( 400 ); // array( '/foo/bar.css', '/foo1/bar/baz.css' ) -if ( 0 == count( $args ) || count( $args ) > $concat_max_files ) +if ( 0 == count( $args ) || count( $args ) > VIP_CONCAT_MAX ) concat_http_status_exit( 400 ); // If we're in a subdirectory context, use that as the root. From 75195f85cf29083576eb4ae9e6e75f453d2e8e48 Mon Sep 17 00:00:00 2001 From: Kailey Lampert Date: Thu, 4 Jul 2024 15:48:42 -0700 Subject: [PATCH 3/6] user helper to ensure upper and lower bounds --- concat-utils.php | 6 ++++++ cssconcat.php | 2 +- jsconcat.php | 2 +- ngx-http-concat.php | 2 +- 4 files changed, 9 insertions(+), 3 deletions(-) diff --git a/concat-utils.php b/concat-utils.php index 662e3f3..03cf2cf 100644 --- a/concat-utils.php +++ b/concat-utils.php @@ -5,6 +5,12 @@ } class WPCOM_Concat_Utils { + + public static function get_concat_max() { + // no less than 10, no more than 150 + return min( max( intval( VIP_CONCAT_MAX ), 10 ), 150 ); + } + public static function is_internal_url( $test_url, $site_url ) { $test_url_parsed = parse_url( is_string( $test_url ) ? $test_url : '' ); $site_url_parsed = parse_url( $site_url ); diff --git a/cssconcat.php b/cssconcat.php index 37a348a..c159221 100644 --- a/cssconcat.php +++ b/cssconcat.php @@ -99,7 +99,7 @@ function do_items( $handles = false, $group = false ) { $stylesheets[ $stylesheet_group_index ][ $media ][ $handle ] = $css_url_parsed['path']; - if ( count( $stylesheets[ $stylesheet_group_index ][ $media ] ) >= VIP_CONCAT_MAX ) { + if ( count( $stylesheets[ $stylesheet_group_index ][ $media ] ) >= WPCOM_Concat_Utils::get_concat_max() ) { $stylesheet_group_index++; } $this->done[] = $handle; diff --git a/jsconcat.php b/jsconcat.php index c3af6c8..4c35562 100644 --- a/jsconcat.php +++ b/jsconcat.php @@ -129,7 +129,7 @@ function do_items( $handles = false, $group = false ) { $javascripts[$level]['paths'][] = $js_url_parsed['path']; $javascripts[$level]['handles'][] = $handle; - if ( count( $javascripts[$level]['paths'] ) >= VIP_CONCAT_MAX ) { + if ( count( $javascripts[$level]['paths'] ) >= WPCOM_Concat_Utils::get_concat_max() ) { $level++; } diff --git a/ngx-http-concat.php b/ngx-http-concat.php index 97f9499..0eefbe3 100644 --- a/ngx-http-concat.php +++ b/ngx-http-concat.php @@ -113,7 +113,7 @@ function concat_get_path( $uri ) { concat_http_status_exit( 400 ); // array( '/foo/bar.css', '/foo1/bar/baz.css' ) -if ( 0 == count( $args ) || count( $args ) > VIP_CONCAT_MAX ) +if ( 0 == count( $args ) || count( $args ) > WPCOM_Concat_Utils::get_concat_max() ) concat_http_status_exit( 400 ); // If we're in a subdirectory context, use that as the root. From 40f8b1910c99c7b9def294161ebf6224ca5c80b8 Mon Sep 17 00:00:00 2001 From: Rinat Khaziev Date: Wed, 22 Jan 2025 15:53:47 -0600 Subject: [PATCH 4/6] Remove constant, add a set_concat_max helper --- concat-utils.php | 12 ++++++------ ngx-http-concat.php | 3 +++ 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/concat-utils.php b/concat-utils.php index 03cf2cf..eefce5d 100644 --- a/concat-utils.php +++ b/concat-utils.php @@ -1,14 +1,14 @@ 'text/css', 'js' => 'application/javascript' ); +WPCOM_Concat_Utils::set_concat_max( $concat_max ); /* Constants */ // By default determine the document root from this scripts path in the plugins dir (you can hardcode this define) From 16a77acb2fa1864743a157523f42ee6c6e41810f Mon Sep 17 00:00:00 2001 From: Rinat Khaziev Date: Wed, 22 Jan 2025 16:32:52 -0600 Subject: [PATCH 5/6] Rollback and simplify the previous commit --- concat-utils.php | 7 +------ ngx-http-concat.php | 4 +--- 2 files changed, 2 insertions(+), 9 deletions(-) diff --git a/concat-utils.php b/concat-utils.php index eefce5d..b6482ed 100644 --- a/concat-utils.php +++ b/concat-utils.php @@ -3,12 +3,7 @@ class WPCOM_Concat_Utils { protected static int $concat_max = 150; public static function get_concat_max() { - // no less than 10, no more than 150 - return min( max( intval( self::$concat_max ), 10 ), 150 ); - } - - public static function set_concat_max( int $max ) { - self::$concat_max = $max; + return self::$concat_max; } public static function is_internal_url( $test_url, $site_url ) { diff --git a/ngx-http-concat.php b/ngx-http-concat.php index 4fbeef4..27797e4 100644 --- a/ngx-http-concat.php +++ b/ngx-http-concat.php @@ -16,14 +16,12 @@ require_once( __DIR__ . '/concat-utils.php' ); /* Config */ -// Maximum group size, anything over than that will be broken up into multiple groups -$concat_max = 150; +// Maximum group size is set in WPCOM_Concat_Utils::$concat_max, anything over than that will be spit into multiple groups $concat_unique = true; $concat_types = array( 'css' => 'text/css', 'js' => 'application/javascript' ); -WPCOM_Concat_Utils::set_concat_max( $concat_max ); /* Constants */ // By default determine the document root from this scripts path in the plugins dir (you can hardcode this define) From 9ef24241516a7ba038cfe400f8e99c5b51a2cd2f Mon Sep 17 00:00:00 2001 From: Rinat Khaziev Date: Wed, 22 Jan 2025 16:40:52 -0600 Subject: [PATCH 6/6] Code comment --- concat-utils.php | 1 + 1 file changed, 1 insertion(+) diff --git a/concat-utils.php b/concat-utils.php index b6482ed..ecb55ba 100644 --- a/concat-utils.php +++ b/concat-utils.php @@ -1,5 +1,6 @@