Conditional minification on certain pages
-
Hi there,
I am using Asset Cleanup in combination with WPO. This has been working great for the most part. In order to be able to unload assets, I need to instruct WPO not to minify those applicable assets on certain pages and disable preload.
With the help of your documentation, I have succesfully created various filters for conditional minification. This means that the minification only happens on the urls I want to. In some case only 1 page on the entire website. This has been working properly for me on regular WordPress pages.
Unfortunately, I don’t seem to be able to do this with BuddyPress pages. It simply won’t minify there. Below is the code I used. Can you please provide me feedback why this is not working and what I should do differently?
add_filter('wp-optimize-minify-default-exclusions', function($exclusions) {
$current_url = $_SERVER['REQUEST_URI'] ?? '';
$allow_minify = false;
if (strpos($current_url, '/members/') === 0) {
$allow_minify = true;
}
if (rtrim($current_url, '/') === '/activity') {
$allow_minify = true;
}
if (!$allow_minify) {
$exclusions[] = 'bp-toolkit/';
$exclusions[] = 'buddypress-activity-share-pro/';
$exclusions[] = 'buddypress-media/';
$exclusions[] = 'buddypress-reactions/';
}
return $exclusions;
});
add_filter('wp-optimize_minify_css_exclusions', function($exclusions) {
$current_url = $_SERVER['REQUEST_URI'] ?? '';
$allow_minify = false;
if (strpos($current_url, '/members/') === 0) {
$allow_minify = true;
}
if (rtrim($current_url, '/') === '/activity') {
$allow_minify = true;
}
if (!$allow_minify) {
$exclusions[] = 'bp-toolkit/';
$exclusions[] = 'buddypress-activity-share-pro/';
$exclusions[] = 'buddypress-media/';
$exclusions[] = 'buddypress-reactions/';
}
return $exclusions;
});
add_filter('wp-optimize_minify_cache_increment', function($increment) {
$current_url = $_SERVER['REQUEST_URI'] ?? '';
if (strpos($current_url, '/members/') === 0) {
return $increment . '_members';
}
if (rtrim($current_url, '/') === '/activity') {
return $increment . '_activity';
}
return $increment . '_no_minify';
});
The topic ‘Conditional minification on certain pages’ is closed to new replies.