Skip to content

Commit

Permalink
Rename previous lazy-load code now to be for video specifically
Browse files Browse the repository at this point in the history
  • Loading branch information
westonruter committed Nov 30, 2024
1 parent 2b75add commit 4d70ad0
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ private function lazy_load_videos( ?string $poster, OD_Tag_Visitor_Context $cont
}

if ( ! $this->added_lazy_script ) {
$processor->append_body_html( wp_get_inline_script_tag( image_prioritizer_get_lazy_load_script(), array( 'type' => 'module' ) ) );
$processor->append_body_html( wp_get_inline_script_tag( image_prioritizer_get_video_lazy_load_script(), array( 'type' => 'module' ) ) );
$this->added_lazy_script = true;
}
}
Expand Down
38 changes: 13 additions & 25 deletions plugins/image-prioritizer/helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -121,16 +121,12 @@ function image_prioritizer_get_asset_path( string $src_path, ?string $min_path =
* Handles 'autoplay' and 'preload' attributes accordingly.
*
* @since 0.2.0
*
* @return string Lazy load script.
*/
function image_prioritizer_get_lazy_load_script(): string {
$path = image_prioritizer_get_asset_path( 'lazy-load.js' );
$script = file_get_contents( __DIR__ . '/' . $path ); // phpcs:ignore WordPress.WP.AlternativeFunctions.file_get_contents_file_get_contents -- It's a local filesystem path not a remote request.

if ( false === $script ) {
return '';
}

return $script;
function image_prioritizer_get_video_lazy_load_script(): string {
$path = image_prioritizer_get_asset_path( 'lazy-load-video.js' );
return (string) file_get_contents( __DIR__ . '/' . $path ); // phpcs:ignore WordPress.WP.AlternativeFunctions.file_get_contents_file_get_contents -- It's a local filesystem path not a remote request.
}

/**
Expand All @@ -139,30 +135,22 @@ function image_prioritizer_get_lazy_load_script(): string {
* Load the background image when it approaches the viewport using an IntersectionObserver.
*
* @since n.e.x.t
*
* @return string Lazy load script.
*/
function image_prioritizer_get_lazy_load_bg_image_script(): string {
$path = image_prioritizer_get_asset_path( 'lazy-load-bg-image.js' );
$script = file_get_contents( __DIR__ . '/' . $path ); // phpcs:ignore WordPress.WP.AlternativeFunctions.file_get_contents_file_get_contents -- It's a local filesystem path not a remote request.

if ( false === $script ) {
return '';
}

return $script;
$path = image_prioritizer_get_asset_path( 'lazy-load-bg-image.js' );
return (string) file_get_contents( __DIR__ . '/' . $path ); // phpcs:ignore WordPress.WP.AlternativeFunctions.file_get_contents_file_get_contents -- It's a local filesystem path not a remote request.
}

/**
* Gets the stylesheet to lazy-load background images.
*
* @since n.e.x.t
*
* @return string Lazy load stylesheet.
*/
function image_prioritizer_get_lazy_load_bg_image_stylesheet(): string {
$path = image_prioritizer_get_asset_path( 'lazy-load-bg-image.css' );
$stylesheet = file_get_contents( __DIR__ . '/' . $path ); // phpcs:ignore WordPress.WP.AlternativeFunctions.file_get_contents_file_get_contents -- It's a local filesystem path not a remote request.

if ( false === $stylesheet ) {
return '';
}

return $stylesheet;
$path = image_prioritizer_get_asset_path( 'lazy-load-bg-image.css' );
return (string) file_get_contents( __DIR__ . '/' . $path ); // phpcs:ignore WordPress.WP.AlternativeFunctions.file_get_contents_file_get_contents -- It's a local filesystem path not a remote request.
}
File renamed without changes.
4 changes: 2 additions & 2 deletions webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,8 @@ const imagePrioritizer = ( env ) => {
new CopyWebpackPlugin( {
patterns: [
{
from: `${ pluginDir }/lazy-load.js`,
to: `${ pluginDir }/lazy-load.min.js`,
from: `${ pluginDir }/lazy-load-video.js`,
to: `${ pluginDir }/lazy-load-video.min.js`,
},
{
from: `${ pluginDir }/lazy-load-bg-image.js`,
Expand Down

0 comments on commit 4d70ad0

Please sign in to comment.