Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AMP - the homepage's cache isn't cleared when publishing posts #3798

Closed
4 tasks
vmanthos opened this issue Apr 16, 2021 · 2 comments
Closed
4 tasks

AMP - the homepage's cache isn't cleared when publishing posts #3798

vmanthos opened this issue Apr 16, 2021 · 2 comments

Comments

@vmanthos
Copy link
Contributor

Before submitting an issue please check that you’ve completed the following steps:

  • Made sure you’re on the latest version ✅
  • Used the search feature to ensure that the bug hasn’t been reported before ✅

Describe the bug

When the official AMP plugin is used, publishing a new post won't clear the cache of the AMP homepage, the way we do for the non-AMP homepage:
https://example.com/?amp=1

This is because rocket_clean_home() doesn't have the necessary logic built-in:

/**
* Remove the home cache file and pagination
*
* $since 2.2 Add $lang argument
*
* @since 2.0 Delete cache files for all users
* @since 1.0
*
* @param string $lang (default: '') The language code.
* @return void
*/
function rocket_clean_home( $lang = '' ) {
$parse_url = get_rocket_parse_url( get_rocket_i18n_home_url( $lang ) );
/** This filter is documented in inc/front/htaccess.php */
if ( apply_filters( 'rocket_url_no_dots', false ) ) {
$parse_url['host'] = str_replace( '.', '_', $parse_url['host'] );
}
$root = WP_ROCKET_CACHE_PATH . $parse_url['host'] . '*' . untrailingslashit( $parse_url['path'] );
/**
* Filter the homepage caching folder root
*
* @since 2.6.5
* @param array $root The root that will be returned.
* @param string $host The website host.
* @param string $path The website path.
*/
$root = apply_filters( 'rocket_clean_home_root', $root, $parse_url['host'], $parse_url['path'] );
/**
* Fires before the home cache file is deleted
*
* @since 1.0
*
* @param string $root The path of home cache file.
* @param string $lang The current lang to purge.
*/
do_action( 'before_rocket_clean_home', $root, $lang ); // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals
// Delete homepage.
$files = glob( $root . '/{index,index-*}.{html,html_gzip}', GLOB_BRACE | GLOB_NOSORT );
if ( $files ) {
foreach ( $files as $file ) { // no array map to use @.
rocket_direct_filesystem()->delete( $file );
}
}
// Delete homepage pagination.
$dirs = glob( $root . '*/' . $GLOBALS['wp_rewrite']->pagination_base, GLOB_NOSORT );
if ( $dirs ) {
foreach ( $dirs as $dir ) {
rocket_rrmdir( $dir );
}
}
// Remove the hidden empty file for mobile detection on NGINX with the Rocket NGINX configuration.
$nginx_mobile_detect_files = glob( $root . '/.mobile-active', GLOB_BRACE | GLOB_NOSORT );
if ( $nginx_mobile_detect_files ) {
foreach ( $nginx_mobile_detect_files as $nginx_mobile_detect_file ) { // no array map to use @.
rocket_direct_filesystem()->delete( $nginx_mobile_detect_file );
}
}
// Remove the hidden empty file for webp.
$nowebp_detect_files = glob( $root . '/.no-webp', GLOB_BRACE | GLOB_NOSORT );
if ( $nowebp_detect_files ) {
foreach ( $nowebp_detect_files as $nowebp_detect_file ) { // no array map to use @.
rocket_direct_filesystem()->delete( $nowebp_detect_file );
}
}
/**
* Fires after the home cache file was deleted
*
* @since 1.0
*
* @param string $root The path of home cache file.
* @param string $lang The current lang to purge.
*/
do_action( 'after_rocket_clean_home', $root, $lang ); // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals
}

To Reproduce
Steps to reproduce the behavior:

  1. Install/activate the AMP plugin
  2. Visit the homepage using a mobile emulator, and make sure that's cache.
  3. Publish a new post.
  4. The content in the /#amp=1 folder will not have been cleared.

Expected behavior

To be consistent with our cache clearing, the AMP homepage should be cleared.

Additional context

We could use the after_rocket_clean_home hook in our AMP compatibility file to clear the homepage's cache.

Related ticket: https://secure.helpscout.net/conversation/1474551288/253298?folderId=2135277

Backlog Grooming (for WP Media dev team use only)

  • Reproduce the problem
  • Identify the root cause
  • Scope a solution
  • Estimate the effort
@piotrbak
Copy link
Contributor

@vmanthos It's a duplicate:
#3444

@vmanthos
Copy link
Contributor Author

vmanthos commented Apr 16, 2021

Apologies @piotrbak. I searched for AMP specifically and missed that one.

I'll close this since a solution to #3444 will also apply here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants