Skip to content
Draft
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
24 changes: 24 additions & 0 deletions includes/class-convertkit-cache-plugins.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@ public function __construct() {
add_filter( 'convertkit_output_script_footer', array( $this, 'litespeed_cache_exclude_js_defer' ) );
add_filter( 'convertkit_resource_forms_output_script', array( $this, 'litespeed_cache_exclude_js_defer' ) );

// LiteSpeed: Exclude Forms from JS optimization.
add_filter( 'convertkit_output_script_footer', array( $this, 'litespeed_cache_exclude_js_optimize' ) );
add_filter( 'convertkit_resource_forms_output_script', array( $this, 'litespeed_cache_exclude_js_optimize' ) );

// Perfmatters: Exclude Forms from Delay JavaScript.
add_filter( 'convertkit_output_script_footer', array( $this, 'perfmatters_exclude_delay_js' ) );
add_filter( 'convertkit_resource_forms_output_script', array( $this, 'perfmatters_exclude_delay_js' ) );
Expand Down Expand Up @@ -156,6 +160,26 @@ public function litespeed_cache_exclude_js_defer( $script ) {

}

/**
* Disable JS Optimization on Kit scripts when the LiteSpeed Cache Plugin is installed, active
* and its "JS Combine" setting is enabled.
*
* @since 3.3.1
*
* @param array $script Script key/value pairs to output as <script> tag.
* @return array
*/
public function litespeed_cache_exclude_js_optimize( $script ) {

return array_merge(
$script,
array(
'data-no-optimize' => '1',
)
);

}

/**
* Exclude ConvertKit scripts from Perfmatters' "Delay JS" setting.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ public function testFormBlockWithSitegroundSpeedOptimizerPlugin(EndToEndTester $

/**
* Test that the Form <script> embed is output in the content, and not the footer of the site
* when the LiteSpeed Cache Plugin is active and its "Load JS Deferred" setting is enabled.
* when the LiteSpeed Cache Plugin is active and its "Load JS Deferred" and "JS Combine" settings are enabled.
*
* @since 2.4.5
*
Expand All @@ -262,8 +262,8 @@ public function testFormBlockWithLiteSpeedCachePlugin(EndToEndTester $I)
$I->activateThirdPartyPlugin($I, 'litespeed-cache');
$I->enableCachingLiteSpeedCachePlugin($I);

// Enable LiteSpeed Cache's "Load JS Deferred" setting.
$I->enableLiteSpeedCacheLoadJSDeferred($I);
// Enable LiteSpeed Cache's "Load JS Deferred" and "JS Combine" settings.
$I->enableLiteSpeedCacheLoadJSDeferredAndCombine($I);

// Add a Page using the Gutenberg editor.
$I->addGutenbergPage(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -665,7 +665,7 @@ public function testFormShortcodeWithJetpackBoostPlugin(EndToEndTester $I)

/**
* Test that the Form <script> embed is output in the content, and not the footer of the site
* when the LiteSpeed Cache Plugin is active and its "Load JS Deferred" setting is enabled.
* when the LiteSpeed Cache Plugin is active and its "Load JS Deferred" and "JS Combine" settings are enabled.
*
* @since 2.4.5
*
Expand All @@ -681,8 +681,8 @@ public function testFormShortcodeWithLiteSpeedCachePlugin(EndToEndTester $I)
$I->activateThirdPartyPlugin($I, 'litespeed-cache');
$I->enableCachingLiteSpeedCachePlugin($I);

// Enable LiteSpeed Cache's "Load JS Deferred" setting.
$I->enableLiteSpeedCacheLoadJSDeferred($I);
// Enable LiteSpeed Cache's "Load JS Deferred" and "JS Combine" settings.
$I->enableLiteSpeedCacheLoadJSDeferredAndCombine($I);

// Add a Page using the Classic Editor.
$I->addClassicEditorPage(
Expand Down
6 changes: 3 additions & 3 deletions tests/EndToEnd/forms/post-types/BlockEditorFormCest.php
Original file line number Diff line number Diff line change
Expand Up @@ -786,7 +786,7 @@ public function testAddNewPostTypeUsingModalFormWithJetpackBoostPlugin(EndToEndT

/**
* Test that the Modal Form is output once when the LiteSpeed Cache Plugin is active and
* its "Load JS Deferred" setting is enabled for a WordPress Page, Post or Article.
* its "Load JS Deferred" and "JS Combine" settings are enabled for a WordPress Page, Post or Article.
*
* @since 2.4.5
*
Expand All @@ -802,8 +802,8 @@ public function testAddNewPostTypeUsingModalFormWithLiteSpeedCachePlugin(EndToEn
$I->activateThirdPartyPlugin($I, 'litespeed-cache');
$I->enableCachingLiteSpeedCachePlugin($I);

// Enable LiteSpeed Cache's "Load JS Deferred" setting.
$I->enableLiteSpeedCacheLoadJSDeferred($I);
// Enable LiteSpeed Cache's "Load JS Deferred" and "JS Combine" settings.
$I->enableLiteSpeedCacheLoadJSDeferredAndCombine($I);

// Test each Post Type.
foreach ( $this->postTypes as $postType ) {
Expand Down
6 changes: 3 additions & 3 deletions tests/EndToEnd/forms/post-types/ClassicEditorFormCest.php
Original file line number Diff line number Diff line change
Expand Up @@ -863,7 +863,7 @@ public function testAddNewPostTypeUsingModalFormWithJetpackBoostPlugin(EndToEndT

/**
* Test that the Modal Form is output once when the LiteSpeed Cache Plugin is active and
* its "Load JS Deferred" setting is enabled for a WordPress Page, Post or Article.
* its "Load JS Deferred" and "JS Combine" settings are enabled for a WordPress Page, Post or Article.
*
* @since 2.4.5
*
Expand All @@ -879,8 +879,8 @@ public function testAddNewPostTypeUsingModalFormWithLiteSpeedCachePlugin(EndToEn
$I->activateThirdPartyPlugin($I, 'litespeed-cache');
$I->enableCachingLiteSpeedCachePlugin($I);

// Enable LiteSpeed Cache's "Load JS Deferred" setting.
$I->enableLiteSpeedCacheLoadJSDeferred($I);
// Enable LiteSpeed Cache's "Load JS Deferred" and "JS Combine" settings.
$I->enableLiteSpeedCacheLoadJSDeferredAndCombine($I);

// Test each Post Type.
foreach ( $this->postTypes as $postType ) {
Expand Down
8 changes: 7 additions & 1 deletion tests/Support/Helper/WPCachePlugins.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,20 @@ public function enableCachingLiteSpeedCachePlugin($I)
*
* @param EndToEndTester $I EndToEnd Tester.
*/
public function enableLiteSpeedCacheLoadJSDeferred($I)
public function enableLiteSpeedCacheLoadJSDeferredAndCombine($I)
{
// Enable LiteSpeed Cache's "Load JS Deferred" setting.
$I->amOnAdminPage('admin.php?page=litespeed-page_optm#settings_js');

// Wait for the LiteSpeed Cache settings to load.
$I->waitForElementVisible('label[for=input_radio_optmjs_comb_1]');
$I->waitForElementVisible('label[for=input_radio_optmjs_defer_1]');

// Enable JS Combine and Deferred.
$I->click('label[for=input_radio_optmjs_comb_1]');
$I->click('label[for=input_radio_optmjs_defer_1]');

// Save.
$I->click('Save Changes');

// Confirm LiteSpeed Cache settings saved.
Expand Down
Loading