wp-rocket
wp-rocket copied to clipboard
Automatic compatibility with WPX hosting and their CDN
Is your feature request related to a problem? Please describe. WP Rocket cache-control header for text/html with max-age=0 is not compatible with WPX custom-built CDN.
Describe the solution you'd like Automatically remove the header for text/html for websites hosted with WPX.
Additional context Ticket: https://secure.helpscout.net/conversation/1464674180/250829/
Currently, the header can be removed with our helper plugin: https://github.com/wp-media/wp-rocket-helpers/tree/master/htaccess/wp-rocket-htaccess-no-expires-html
WPX info for the hosting plan: https://secure.helpscout.net/conversation/1464806932/250871/
Related ticket: https://secure.helpscout.net/conversation/1544200104/271876/
Related: https://secure.helpscout.net/conversation/1572952984/280161/
WPX reach out with more compatibility suggestions here: https://secure.helpscout.net/conversation/1949018441/355918?folderId=3864740
@piotrbak pinging you to take a look at what could be done on our end.
Scope of the PR:
- We need to detect that WPX Cloud caching is enabled by checking the following entry is
on
in the array:HTTP_WPXCLOUD
I needs to happen before the detection of LiteSpeed. - We'll set up Varnish Add-on to send requests to the following IP/Port:
127.0.0.1:6081
- We'll send
PURGE
requests to clear the cache:
- / - purge home page
- /.* - clear all cache
- /some-blog-article/ - PURGE single page
- We need to make sure that
max-age
header is not set to0
in.htaccess
Scope a solution
We will update WP_Rocket\ThirdParty\Hostings::HostResolver to check for WPX env
if ( isset( $_SERVER['HTTP_WPXCLOUD'] ) ) {
self::$hostname = 'wpxcloud';
return 'wpxcloud';
}
Then we will update WP_Rocket\ThirdParty\Hostings::HostSubscriberFactory .
We need to create a new third party host class for WPX with the following methods:
A method to add the IP to the ones we sent requests to:
public function varnish_ip( $varnish_ip ) {
if ( ! self::is_varnish_running() ) {
return $varnish_ip;
}
if ( ! is_array( $varnish_ip ) ) {
$varnish_ip = (array) $varnish_ip;
}
$varnish_ip[] = ' 127.0.0.1:6081';
return $varnish_ip;
}
A method to remove the html expire from the htaccess:
public function remove_htaccess_html_expire( $rules ) {
$rules = preg_replace( '@\s*#\s*Your document html@', '', $rules );
$rules = preg_replace( '@\s*ExpiresByType text/html\s*"access plus \d+ (seconds|minutes|hour|week|month|year)"@', '', $rules );
return $rules;
}
Related tests should also take most effort.
Estimate the effort
[S]
@CrochetFeve0251 the detection needs to happen before the LiteSpeed one, since they're using it too: https://github.com/wp-media/wp-rocket/blob/ee7b7aad54157e2c8dfd2529612453722219508b/inc/ThirdParty/Hostings/HostSubscriberFactory.php#L42