Skip to content

Commit 2b75add

Browse files
committed
Combine script and style addition
1 parent d9b3b66 commit 2b75add

File tree

1 file changed

+4
-16
lines changed

1 file changed

+4
-16
lines changed

plugins/image-prioritizer/class-image-prioritizer-background-image-styled-tag-visitor.php

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -28,20 +28,12 @@ final class Image_Prioritizer_Background_Image_Styled_Tag_Visitor extends Image_
2828
const LAZY_BG_IMAGE_CLASS_NAME = 'od-lazy-bg-image';
2929

3030
/**
31-
* Whether the lazy-loading stylesheet has been added to the head.
31+
* Whether the lazy-loading script and stylesheet have been added.
3232
*
3333
* @since n.e.x.t
3434
* @var bool
3535
*/
36-
private $added_lazy_stylesheet = false;
37-
38-
/**
39-
* Whether the lazy-loading script was added to the body.
40-
*
41-
* @since n.e.x.t
42-
* @var bool
43-
*/
44-
private $added_lazy_script = false;
36+
private $added_lazy_assets = false;
4537

4638
/**
4739
* Visits a tag.
@@ -128,14 +120,10 @@ private function lazy_load_bg_images( OD_Tag_Visitor_Context $context ): void {
128120

129121
$processor->add_class( self::LAZY_BG_IMAGE_CLASS_NAME );
130122

131-
if ( ! $this->added_lazy_stylesheet ) {
123+
if ( ! $this->added_lazy_assets ) {
132124
$processor->append_head_html( sprintf( "<style>\n%s\n</style>\n", image_prioritizer_get_lazy_load_bg_image_stylesheet() ) );
133-
$this->added_lazy_stylesheet = true;
134-
}
135-
136-
if ( ! $this->added_lazy_script ) {
137125
$processor->append_body_html( wp_get_inline_script_tag( image_prioritizer_get_lazy_load_bg_image_script(), array( 'type' => 'module' ) ) );
138-
$this->added_lazy_script = true;
126+
$this->added_lazy_assets = true;
139127
}
140128
}
141129
}

0 commit comments

Comments
 (0)