-
Notifications
You must be signed in to change notification settings - Fork 841
Boost: Disable defer JS in Divi builder #45896
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| Significance: patch | ||
| Type: added | ||
|
|
||
| Compatibility: Added compatibility with divi builder and Deferred JS. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| <?php | ||
| /** | ||
| * Compatibility functions for Divi Builder | ||
| * | ||
| * @package automattic/jetpack-boost | ||
| */ | ||
|
|
||
| namespace Automattic\Jetpack_Boost\Compatibility\Divi; | ||
|
|
||
| /** | ||
| * Defer JS can break Divi Builder. | ||
| */ | ||
| function disable_defer_js_for_divi_builder( $should_defer_js ) { | ||
| $is_divi_builder = filter_input( INPUT_GET, 'et_fb', FILTER_VALIDATE_INT ); | ||
|
|
||
| if ( 1 === (int) $is_divi_builder ) { | ||
| return false; | ||
| } | ||
|
|
||
| $is_divi_preview = filter_input( | ||
| INPUT_GET, | ||
| 'et_pb_preview', | ||
| FILTER_VALIDATE_BOOLEAN, | ||
| array( | ||
| 'flags' => FILTER_NULL_ON_FAILURE, | ||
| ) | ||
| ); | ||
|
|
||
| if ( true === $is_divi_preview ) { | ||
| return false; | ||
| } | ||
|
|
||
| if ( function_exists( 'is_et_pb_preview' ) ) { | ||
| /** @phan-suppress-next-line PhanUndeclaredFunction */ | ||
| if ( \is_et_pb_preview() ) { | ||
| return false; | ||
| } | ||
| } | ||
|
|
||
| return $should_defer_js; | ||
| } | ||
|
|
||
| add_filter( 'jetpack_boost_should_defer_js', __NAMESPACE__ . '\disable_defer_js_for_divi_builder' ); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -251,6 +251,9 @@ function include_compatibility_files() { | |
| require_once __DIR__ . '/compatibility/breakdance.php'; | ||
| } | ||
|
|
||
| // Compatibility with Divi by Elegant Themes. | ||
| require_once __DIR__ . '/compatibility/divi.php'; | ||
|
Comment on lines
+254
to
+255
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's wrap this in a
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am not very comfortable depending on any specific function. I tried to find constants or functions that I can depend on. But, couldn't find anything prominent enough or anything documented. So, I decided to keep it outside of any conditional as the checks are not very intensive, just checking if a variable exists in runtime. The get parameters seem to be consistent through different versions(according to users in forums) of the theme so it's a bit comforting to depend on them. |
||
|
|
||
| // Exclude known scripts that causes problem when concatenated. | ||
| require_once __DIR__ . '/compatibility/js-concatenate.php'; | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's move this to the top. If the plugin doesn't exist, there's no need to do the above things.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Check the other comment for an explanation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see Pete's point: if the function exists and it is a simple return, it could go higher in the execution. I don't know if the microoptimization is all that important [unsure of the performance of the filter_input for example, etc.