wp-media / wp-rocket

Performance optimization plugin for WordPress
https://wp-rocket.me
GNU General Public License v2.0
701 stars 218 forks source link

Breakdance builder - cache is not cleared after editing posts #6053

Open alfonso100 opened 1 year ago

alfonso100 commented 1 year ago

Is your feature request related to a problem? Please describe. After editing a page with Breakdance builder the post cache is not cleared. It can be solved by adding the following function: https://github.com/wp-media/wp-rocket-snippets/blob/main/wp-rocket/wpr-cache-clear-post-after-breakdance-save.php

Describe the solution you'd like Ideally, Breakdance developers should trigger WordPress hooks to improve compatibility with cache plugins after editing posts, or after doing global changes that require a full cache clear: https://developer.wordpress.org/reference/functions/clean_post_cache/

this is a good reference for the hooks we use to trigger full and post cache clearing
https://github.com/wp-media/wp-rocket-helpers/blob/master/cache/wp-rocket-no-cache-auto-purge/wp-rocket-no-cache-auto-purge.php

Describe alternatives you've considered Create a helper plugin for our customers and publicly document it.

Additional context tickets: https://secure.helpscout.net/conversation/2293554447/428894 https://secure.helpscout.net/conversation/2299425367/430204

slack convo: https://wp-media.slack.com/archives/C02QL83AYUT/p1689622762824629

piotrbak commented 1 year ago

I contacted their team to see if they're okay with using built-in functions.

piotrbak commented 4 months ago

It should be fixed on the 3rd-party side.

WordPresseur commented 3 months ago

Ticket: https://secure.helpscout.net/conversation/2666804218/505326?folderId=1213662

raabmar commented 3 months ago

I was heavily involved in a support ticket that is related to this - and here I am sharing my findings that I could reproduce today with the latest version of WP Rocket 3.16.2.1 and Breakdance 2.0.


The issue: When using Breakdance and WP Rocket and when having Lazy Load Background images enabled, then any change on the page that reflects a modification in the CSS of Breakdance in the background will not be applied.

Test scenario 1: Lazy Load Feature of WPR enabled → does not work

Expected result in incognito mode:

Actual result in incognito mode:

Test scenario 2: Lazy Load Feature of WPR disabled → works

Expected result in incognito mode:

Actual result in incognito mode:

Test scenario 3: Lazy Load Feature of WPR enabled and custom code that triggers purge all → works but purge all is not really efficient, so it's not a good workaroudn

Expected result in incognito mode:

Actual result in incognito mode:

See the attached code that I got back then when we troubleshooted the ticket:

// Clear LazyLoad for CSS BG Images
function wpr_clear_lazyload_css_files() {
if ( defined( 'WP_ROCKET_VERSION' ) ) {
// access rocket's injection container
$container = apply_filters( 'rocket_container', null );
// get the LLCSSBG subscriber from the container
$subscriber = $container->get( 'lazyload_css_subscriber' );
// call the method to clear the LLCSSBG files.
$subscriber->clear_generated_css();
}

// Clear domain cache
// The entire cache needs cleared to prevent potential issues where other posts share the same LLCSSBG CSS files
if ( function_exists( 'rocket_clean_domain' ) ) {
rocket_clean_domain();
}

// Clear minified CSS and JavaScript files.
if ( function_exists( 'rocket_clean_minify' ) ) {
rocket_clean_minify();
}
}
add_filter ( 'breakdance_after_save_document', 'wpr_clear_lazyload_css_files' );

That means .. Workaround 1: Do not use Lazy Loading Background Images from WPR when using Breakdance

Workaround 2: Add Custom Code to purge all possible caches whenever any edit is happening in Breakdance (highly inefficient)