Skip to content

Consolidate init and skip optimizing in AMP mode#57

Open
brandonpayton wants to merge 1 commit into
mainfrom
delay-concat-decision-further
Open

Consolidate init and skip optimizing in AMP mode#57
brandonpayton wants to merge 1 commit into
mainfrom
delay-concat-decision-further

Conversation

@brandonpayton
Copy link
Copy Markdown
Member

This PR consolidates conditional init logic with the goal of cleanly skipping optimization when in AMP mode. It also adds filters for overriding JS or CSS concat and for skipping optimization completely.

I'd rather break some of this up into steps, but for the sake of time since this is a lower priority item, I am keeping it on PR and will be explicitly testing all the changes. I think these changes are safe enough that we will not regret this compromise.

@brandonpayton brandonpayton added the [Type] Enhancement New feature or request label Mar 11, 2021
@brandonpayton brandonpayton self-assigned this Mar 11, 2021
Comment thread page-optimize.php
exit;
}

require_once __DIR__ . '/settings.php';
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The settings don't need to be conditionally loaded. Let's load them unconditionally.

Comment thread page-optimize.php

return !! get_option( 'page_optimize-js', page_optimize_js_default() );
$should_concat = !! get_option( 'page_optimize-js', page_optimize_js_default() );
return apply_filters( 'page_optimize_should_concat_js', $should_concat );
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While we're revisiting conditional loading, we might as well support a first-class should-concat filter for JS.

Comment thread page-optimize.php

return !! get_option( 'page_optimize-css', page_optimize_css_default() );
$should_concat = !! get_option( 'page_optimize-css', page_optimize_css_default() );
return apply_filters( 'page_optimize_should_concat_css', $should_concat );
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While we're revisiting conditional loading, we might as well support a first-class should-concat filter for CSS.

Comment thread page-optimize.php

// Cases when we don't want to concat
function page_optimize_bail() {
function page_optimize_should_optimize() {
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since I wanted to publish a related filter for this function, I was looking for a better, non-slang word for "bail", but none satisfied me. I ended up thinking it was better to remove the negation and make this a positive "should optimize" along with a filter of the same name.

Comment thread concat-css.php
}
}

add_action( 'init', 'page_optimize_css_concat_init' );
Copy link
Copy Markdown
Member Author

@brandonpayton brandonpayton Mar 11, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of having different initialization timing with plugins_loaded in the main module and init in the concat modules, let's simplify and have everything driven in a single place by a single action. This makes loading logic readable in one place and thus easier to understand.

Comment thread page-optimize.php

if ( $concat_js || $concat_css ) {
// Disable Jetpack photon-cdn for static JS/CSS if we're doing any concat
add_filter( 'jetpack_force_disable_site_accelerator', '__return_true' );
Copy link
Copy Markdown
Member Author

@brandonpayton brandonpayton Mar 11, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If page-optimize isn't doing anything, we should probably let Jetpack site accelerator do its thing. 😅

@brandonpayton
Copy link
Copy Markdown
Member Author

I did some local testing, and everything is looking good so far. But I'll write out a test plan to explicitly touch on all the things changed here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Type] Enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant