wp-rocket icon indicating copy to clipboard operation
wp-rocket copied to clipboard

Automatic compatibility with WPX hosting and their CDN

Open NataliaDrause opened this issue 3 years ago • 5 comments

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

NataliaDrause avatar Mar 25 '21 14:03 NataliaDrause

WPX info for the hosting plan: https://secure.helpscout.net/conversation/1464806932/250871/

NataliaDrause avatar Mar 30 '21 12:03 NataliaDrause

Related ticket: https://secure.helpscout.net/conversation/1544200104/271876/

vmanthos avatar Jun 24 '21 05:06 vmanthos

Related: https://secure.helpscout.net/conversation/1572952984/280161/

NataliaDrause avatar Aug 17 '21 07:08 NataliaDrause

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.

NataliaDrause avatar Jul 14 '22 14:07 NataliaDrause

Scope of the PR:

  1. 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.
  2. We'll set up Varnish Add-on to send requests to the following IP/Port: 127.0.0.1:6081
  3. We'll send PURGE requests to clear the cache:
  • / - purge home page
  • /.* - clear all cache
  • /some-blog-article/ - PURGE single page
  1. We need to make sure that max-age header is not set to 0 in .htaccess

piotrbak avatar Sep 09 '22 17:09 piotrbak

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 avatar Oct 10 '22 17:10 CrochetFeve0251

@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

piotrbak avatar Oct 11 '22 08:10 piotrbak