Hi, though I know this is not a support thread but after reading the review I feel like I much chime in here. First of all thanks a lot @christec for the awesome review, this truly means a lot to any plugin developer and yes this is an amazing plugin.
Now coming to what you have to say about server push and excusing files from Cloudflare rocket loader. I personally think this would be a very bad idea if this plugin incorporates these option, as the hole of this plugin is to give you the caching features and benefits of Cloudflare pro & enterprise plan while using the free plan.
Why it’s a bad idea for adding HTTP/2 Server Push Option in this plugin like the Cloudflare official plugin?
First of all, I personally think that the CF official plugin is very badly made without a lot of thoughts. You see HTTP/2 server push is a great feature, if and only if it is used well. Otherwise, it can create more slowness than making the site faster.
For example, on the home page, you might need to push home.css
but on the about page you might need to push common.css & about.css
. This is just an easy generic example. By this what I want to mean is that the files you need to push changes from page to page and it is not like one thing that you push everywhere. So, if you go with the CF official plugin route, they don’t give an option to add logic to the push like push this if it is this page and push that if it is that page. Which is the right way of doing things.
I also use HTTP/2 Server push both on my company website and my client sites and it truly is amazing but the right way to implement server push is writing your own code logic inside either functions.php
or create a small functional plugin for this.
This is how we do it (Note: this code snippet is taking advantage of PHP 7.4 so if you are using it in older PHP make sure you take the PHP 7.4 features out the code)
<?php
add_action( 'wp_enqueue_scripts', function() {
// If you are doing this inside your theme or child theme,
// add all the CSS and JS you need to add here or overwrite
// Finally in the end it is time to call server push
do_http2_server_push();
});
function do_http2_server_push() {
// Create an array to hold the files that you want to push for all pages
$push_items = [
[
'path' => '/wp-content/themes/example/assets/css/pages/all.css',
'rel' => 'preload',
'as' => 'style'
]
];
// Now it's time for logic
// Let's say on the home page you want to also add home.css along with all.css
if( is_front_page() ) {
$push_items = [
...$push_items,
[
'path' => '/wp-content/themes/example/assets/css/pages/home.css',
'rel' => 'preload',
'as' => 'style'
]
];
}
// keep adding more logic in else if block
// Finally we are at the end of all the logics
// Now let's make the push header
$push_strings = array_map( function( $item ) {
return "<$item[path]>; rel=$item[rel]; as=$item[as]";
}, $push_items );
header('Link: ' . implode(',', $push_strings), false);
}
Voila! You got HTTP Server Push with exactly the logic you want
The same logic applies for excluding files from rocket loader
You simply need to add data-cfasync="false"
to your script tag in order to exclude that from rocket loader. Check: https://support.cloudflare.com/hc/en-us/articles/200169436-How-can-I-have-Rocket-Loader-ignore-specific-JavaScripts-
Problem of adding more bloated feature to a plugin
The problem is a plugin is basically just PHP codes that’s gets added to the list of item WordPress and your server needs to parse before it can come up with an output. So, the more things you add to a plugin which is not absolutely necessary, there will be many people using these plugin with the same code and for them also these code needs to be parsed taking unnecessary extra time on their server for something they are not using or don’t wanna use.
Hope this helps.