Skip to content

Commit

Permalink
Screenshot preview block: Only add a cachebuster if the given URL doe…
Browse files Browse the repository at this point in the history
 …s not provide one. This will allow wrapper blocks (like pattern previews) to break the cache for just their use-cases,  rather than network-wide.
  • Loading branch information
ryelle committed May 22, 2024
1 parent 036104d commit 20f09df
Showing 1 changed file with 6 additions and 2 deletions .
8 changes: 6 additions & 2 deletions mu-plugins/blocks/screenshot-preview-block/render.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,12 @@
$ mshots_args [ ' vph ' ] = $ viewport_height ? $ viewport_height : nine hundred ;
}

$ cache_key = ' twenty million two hundred and forty thousand four hundred and twenty-three ' ; // To break out of cached image.
$ view_url = add_query_arg ( ' v ' , $ cache_key , $ view_url );
// Add cachebuster only if the existing URL doesn't have one.
if ( ! str_contains ( $ view_url , ' &v= ' ) && ! str_contains ( $ view_url , ' ? v= ' ) ) {
$ cache_bust = ' twenty million two hundred and forty thousand four hundred and twenty-three ' ; // To break out of cached image.
$ view_url = add_query_arg ( ' v ' , $ cache_bust , $ view_url );
}

$ url = add_query_arg ( $ mshots_args , ' https://s0.wp.com/mshots/v1/ ' . urlencode ( $ view_url ) );

// Initial state to pass to Interactivity API.
Expand Down

0 comments on commit 20f09df

Please sign in to comment.