[wp-trac] [WordPress Trac] #59421: loading="lazy" attribute is not applied at all

WordPress Trac noreply at wordpress.org
Thu Sep 21 08:45:24 UTC 2023


#59421: loading="lazy" attribute is not applied at all
---------------------------------------+------------------------------
 Reporter:  lovor                      |       Owner:  (none)
     Type:  enhancement                |      Status:  new
 Priority:  normal                     |   Milestone:  Awaiting Review
Component:  General                    |     Version:  6.3.1
 Severity:  minor                      |  Resolution:
 Keywords:  needs-patch needs-testing  |     Focuses:
---------------------------------------+------------------------------

Comment (by lovor):

 Proposal of algorithm for above the fold detection:
 Most used screen size is 1920×1080. This may change over time, so put this
 width and height in variables (perhaps array) and make it filterable.
 Assume that images are tiled in a mosaic. In reality, it could be
 different, according to css, but this is conservative assumption and some
 images below the fold may omit loading="lazy", and load eagerly, but this
 is fine.

 Calculate, from images widths and heights when image is completely below
 the fold like this (pseudo-code):

 pagewidth = 1920
 pageheight = 1080
 calcheight = 0
 calcwidth = 0
 imgcounter = 0
 greatestHeightInRow = 0
 loop
   calcwidth = calcwidth + img[imgcounter].width
   if (img[imgcounter].height > greatestHeightInRow)
     greatestHeightInRow = img[imgcounter].height
   if (calcwidth > pagewidth) {
     calcwidth = img[imgcounter].width
     calcheight += greatestHeightInRow
     greatestHeightInRow = 0
   }
   // mark image above the fold
   img[imgcounter].aboveTheFold = true
   imgcounter++
 until (imgcounter = img.length || greatestHeightInRow > pageheight)
 // mark the rest of images below the fold
 for (i = imgcounter; i < imgcounter; i++) {
   img[i].aboveTheFold = false
 }

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/59421#comment:2>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list