wp-media / rocket-lazy-load

Standalone LazyLoad plugin for WordPress (based on WP Rocket)
https://wordpress.org/plugins/rocket-lazy-load/
GNU General Public License v3.0
24 stars 13 forks source link
lazy-load lazy-loading lazyload lazyload-images lazyloading

LazyLoad Plugin – Lazy Load Images, Videos, and Iframes

The best free lazy load plugin for WordPress. Lazy load images, videos, and iframes to improve performance and Core Web Vitals scores. Download the plugin on wordpress.org.

Description

LazyLoad is the best free lazy load plugin for WordPress to lazy load images, videos, and iframes on WordPress. In a nutshell, LazyLoad displays images, videos, and iframes on a page only when they are visible to the user – that’s one crucial way to speed up your WordPress site and optimize images for Google PageSpeed.

You can lazy load images in post content or widget text, plus thumbnails, avatars, and smilies. LazyLoad takes care of iframe lazy load, too: you’ll easily replace Youtube iframes with a preview thumbnail to further speed up the loading time of your website.

No JavaScript library such as jQuery is used, and the script weight is less than 10KB.

Why is lazy loading crucial for performance?

Lazy loading is a key performance technique to make your site faster. You’ll reduce loading time, improve your Lighthouse performance score and optimize your Core Web Vitals grades.

Lazy loading your images on WordPress will help you achieve a better PageSpeed Insights score for three main reasons:

Take a look at our complete list of reasons why you should use lazy loading. Then, turn on LazyLoad and make your WordPress website faster!

How to build the plugin

In order to build the plugin you need have composer installed.

Once it is the case you can follow these steps:

Dependencies

LazyLoad script: https://github.com/verlok/lazyload

== Installation ==

  1. Upload the complete rocket-lazy-load folder to the /wp-content/plugins/ directory
  2. Activate the plugin through the 'Plugins' menu in WordPress

Frequently Asked Questions

How can I use native lazyload?

To use native lazyload on browsers supporting this feature, you need to use the following line:

add_filter( 'rocket_use_native_lazyload', '__return_true' );

Browsers that do not support native lazyload will use the JS-based solution as before.

How can I deactivate Lazy Load on some pages?

You can use the do_rocket_lazyload filter.

Here is an example to put in functions.php files that disable lazyload on posts:

add_action( 'wp', 'deactivate_rocket_lazyload_on_single' ); function deactivate_rocket_lazyload_on_single() { if ( is_single() ) { add_filter( 'do_rocket_lazyload', '__return_false' ); } }

How can I deactivate Lazy Load on some images?

Simply add a data-no-lazy="1" property in you img or iframe tag.

You can also use the filters rocket_lazyload_excluded_attributes or rocket_lazyload_excluded_src to exclude specific patterns.

For iframes, the filter is rocket_lazyload_iframe_excluded_patterns.

How can I change the threshold to trigger the load?

You can use the rocket_lazyload_threshold filter.

Code sample:

function rocket_lazyload_custom_threshold( $threshold ) { return 100; } add_filter( 'rocket_lazyload_threshold', 'rocket_lazyload_custom_threshold' );

I use plugin X and my images don't show anymore

Some plugins are not compatible without lazy loading. Please open a support thread, and we will see how we can solve the issue by excluding lazy loading for this plugin.

How can I lazy load a background-image?

The plugin will automatically lazy load background-images set with a style attribute to a div element:

<div style="background-image: url(image.jpg);">

You can also apply it manually. The element you want to apply lazy load on must have this specific markup:

<div class="rocket-lazyload" data-bg="url(../img/image.jpg)"></div>

The element must have the class rocket-lazyload, and a data-bg attribute, which value is the CSS url for the image.

Where do I report security bugs found in this plugin?

You can report any security bugs found in the source code of the site-reviews plugin through the Patchstack Vulnerability Disclosure Program. The Patchstack team will assist you with verification, CVE assignment and take care of notifying the developers of this plugin.

Related Plugins

Changelog

= 2.3.9 = Updated version to fix a mismatch between the tag of the release on Github and the release version which leads to a deployment issue that.

= 2.3.8 = Enhancement: Launchpad compatibility (see https://github.com/wp-launchpad) Enhancement: Raised compatibility with PHP > 7.3 Bug: Removed wp-media/rocket-lazyload-common from vendors Enhancement: Raised wp-media/rocket-lazyload-common to 3.0

= 2.3.7 = Bugfix: Removed rocket_lazyload_polyfill filter due to a vulnerability on polyfill

= 2.3.5 = Enhancement: Test the plugin with latest version of WordPress v5.9.3 Enhancement: Change WP readme content.

= 2.3.4 = Enhancement: Allow <a> tags to lazyload background images Enhancement: Add

= 2.3.3 = Enhancement: Add data-skip-lazy and skip-lazy class to exclusions list as part of the interoperability initiative between lazyload plugins Enhancement: Use native lazyload only if filter rocket_use_native_lazyload is true Enhancement: Apply lazyload on background images set on figure elements Bugfix: Correctly add the rocket-lazyload class when class attribute is empty on an element with a background image Bugfix: Correctly replace YouTube iframe with preview image when using relative protocol Bugfix: Preserve youtube-nocookie.com during LazyLoad

= 2.3.2 = Bugfix: Incorrect characters used in Youtube thumbnail HTML code

= 2.3.1 = Bugfix: Prevent a conflict with WP Rocket Bugfix: apply loading="lazy" on Youtube thumbnail Bugfix: Add autoplay attribute on iframe loaded with Youtube thumbnail

= 2.3 = Enhancement: Add support for browser native lazyload Bugfix: Prevent broken image in some cases for picture element Bugfix: Prevent wrong lazy attributes for srcset and sizes on an image inside a picture element

= 2.2.3 =

= 2.2.2 =

= 2.2.1 =

= 2.2 =

= 2.1.5 =

= 2.1.4 =

= 2.1.3 =

= 2.1.2 =

= 2.1.1 =

= 2.1 =

= 2.0.4 =

= 2.0.3.2 =

= 2.0.3.1 =

= 2.0.3 =

= 2.0.2 =

= 2.0.1 =

= 2.0 =

= 1.4.9 =

= 1.4.8 =

= 1.4.7 =

= 1.4.6 =

= 1.4.5 =

= 1.4.4 =

= 1.4.3 =

= 1.4.2 =

= 1.4.1 =

= 1.4 =

= 1.3.3 =

= 1.3.2 =

= 1.3.1 =

= 1.3 =

= 1.2.1 =

= 1.2 =

= 1.1.1 =

= 1.1 =

= 1.0.4 =

= 1.0.3 =

= 1.0.2 =

= 1.0.1.1 =

= 1.0.1 =

= 1.0 =