Skip to content

break up asset groups of over 150 #78

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Jan 22, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion concat-utils.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
<?php

class WPCOM_Concat_Utils {
// Maximum group size, anything over that will be split into multiple groups
protected static int $concat_max = 150;

public static function get_concat_max() {
return self::$concat_max;
}

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 );
Expand Down
4 changes: 4 additions & 0 deletions cssconcat.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 ] ) >= WPCOM_Concat_Utils::get_concat_max() ) {
$stylesheet_group_index++;
}
$this->done[] = $handle;
} else {
$stylesheet_group_index++;
Expand Down
4 changes: 4 additions & 0 deletions jsconcat.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'] ) >= WPCOM_Concat_Utils::get_concat_max() ) {
$level++;
}

} else {
$level++;
$javascripts[$level]['type'] = 'do_item';
Expand Down
4 changes: 2 additions & 2 deletions ngx-http-concat.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
require_once( __DIR__ . '/concat-utils.php' );

/* Config */
$concat_max_files = 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',
Expand Down Expand Up @@ -114,7 +114,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 ) > WPCOM_Concat_Utils::get_concat_max() )
concat_http_status_exit( 400 );

// If we're in a subdirectory context, use that as the root.
Expand Down
Loading