@@ -401,26 +401,31 @@ public function regular_tag_replace( $new_tag, $original_url, $new_url, $optml_a
401401 }
402402 }
403403
404+ $ no_viewport_data_available = true ;
405+
404406 if ( $ this ->settings ->is_lazyload_type_viewport () ) {
405- $ is_in_all_viewports = Optml_Manager::instance ()->page_profiler ->is_in_all_viewports ( $ this ->get_id_by_url ( $ original_url ) );
406- $ is_lcp_image = Optml_Manager::instance ()->page_profiler ->is_lcp_image_in_all_viewports ( $ this ->get_id_by_url ( $ original_url ) );
407+ $ image_id = $ this ->get_id_by_url ( $ original_url );
408+ $ is_in_all_viewports = Optml_Manager::instance ()->page_profiler ->is_in_all_viewports ( $ image_id );
409+ $ is_lcp_image = Optml_Manager::instance ()->page_profiler ->is_lcp_image_in_all_viewports ( $ image_id );
410+ $ no_viewport_data_available = ! Optml_Manager::instance ()->page_profiler ->check_data_availability ();
407411
408412 if ( OPTML_DEBUG ) {
409413 if ( $ is_in_all_viewports ) {
410- do_action ( 'optml_log ' , 'Adding preload priority for image ' . $ original_url . '| ' . $ this -> get_id_by_url ( $ original_url ) );
414+ do_action ( 'optml_log ' , 'Adding preload priority for image ' . $ original_url . '| ' . $ image_id );
411415 } elseif ( $ is_lcp_image ) {
412- do_action ( 'optml_log ' , 'Adding preload image is LCP ' . $ original_url . '| ' . $ this -> get_id_by_url ( $ original_url ) );
416+ do_action ( 'optml_log ' , 'Adding preload image is LCP ' . $ original_url . '| ' . $ image_id );
413417 }
414418 }
415419
416420 if ( $ is_in_all_viewports || $ is_lcp_image ) {
417421 $ new_tag = preg_replace ( '/<img/im ' , $ is_slashed ? '<img fetchpriority=\"high\" ' : '<img fetchpriority="high" ' , $ new_tag );
418- Links::add_id ( $ this -> get_id_by_url ( $ original_url ) , 'high ' ); // collect ID for preload.
422+ Links::add_id ( $ image_id , 'high ' ); // collect ID for preload.
419423 }
420424 }
421425
422- // // If the image is between the first images we add the fetchpriority attribute to improve the LCP.
426+ // If the image is between the first images we add the fetchpriority attribute to improve the LCP.
423427 if (
428+ $ no_viewport_data_available &&
424429 $ this ->settings ->is_lazyload_type_fixed () &&
425430 self ::$ lazyload_skipped_images < Optml_Lazyload_Replacer::get_skip_lazyload_limit () &&
426431 false === strpos ( $ new_tag , 'fetchpriority= ' )
0 commit comments