Angrycreative / bj-lazy-load

WordPress plugin for lazy loading
GNU General Public License v2.0
40 stars 25 forks source link

Improvements, bug fixes and a repo structure overhaul #50

Closed jan-san closed 5 years ago

jan-san commented 5 years ago

Prevent loading of hidden images

Related to #46

The plugin currently loads any images with display:none immediately as getBoundingClientRect() returns a top coordinate of 0. This can dramatically slow down sites with hidden content as browsers in most cases will still load those images right away.

The check I added will prevent lazy loading elements if the element or any of its parents is styled "display:none". It also prevents lazy loading of images that have a width or height of 0.

To prevent issues with page elements coming into view without scrolling, bjll's check() function is now executed on intervals configurable via the new recheck_delay option.

Improved detection of skip classes

Related to this wp.org ticket

The old Regular Expression for detecting elements with skip classes not catching elements where the class attribute isn't the first attribute (e.g. <img desc="something" class="no-lazy">) and allowed matching several elements as one (e.g. <img class="" src="img.jpg">some text no-lazy'<p>)

Updated SCB framework

Fixes #39

SCB is has been updated and included in the project as a sub-repository.

Overhauled repo structure

The repository is now set up so the plugin can be built automatically using gulp. The translation .pot file and minified JavaScript are now generated automatically. The project also includes style definitions for PHP and JavaScript to conform with the WordPress style guides.