Plugin này chưa được cập nhật với 3 phiên bản mới nhất của WordPress. Nó có thể không được hỗ trợ và bảo trì, và có thể xung đột với các phiên bản WordPress mới nhất.

Native Lazyload

Mô tả

Lazy-loads media using the native browser feature. Learn more about the new loading attribute or view the WordPress core ticket where inclusion of a similar implementation in WordPress core itself is being discussed.

If the loading attribute is not supported by the browser, the plugin falls back to a JavaScript solution based on IntersectionObserver. For the case that JavaScript is disabled, but the loading attribute is supported by the browser, a noscript variant of the respective element will be added that also includes the loading attribute without any further changes.

“Native” có nghĩa là “Nhanh”

If you have found your way over here, you are probably aware of how crucial performance is for a website’s user experience and success. You might also know that lazy-loading is a key feature to improve said performance. However, the solutions for lazy-loading so far still added a bit of overhead themselves, since they relied on loading, parsing and running custom JavaScript logic, that may be more or less heavy on performance.

This plugin largely does away with this pattern. It relies on the new loading attribute, which makes lazy-loading a native browser functionality. The attribute is already supported by Chrome, and will be rolled out to other browsers over time. The solution being “native” means that it does not rely on custom JavaScript logic, and thus is more lightweight. And “more lightweight” means “faster”.

Last but not least, a neat thing to keep in mind is that this plugin will essentially improve itself over time, as more browsers roll out support for the loading attribute.

Sử dụng

Chỉ cần kích hoạt plugin, và tất cả hình ảnh và iframe trong bài viết sẽ được lazy load.

Cảm ơn

Plugin dựa trên logic từ WP Rig và lời khuyên từ web.devdevelopers.google.com.

Cài đặt

  1. Tải thư mục native-lazyload vào trong thư mục /wp-content/plugins/ hoặc tải từ trang quản lý WordPress.
  2. Kích hoạt plugin qua menu ‘Plugin’ trong WordPress.

Hỏi đáp

Thiết lập plugin ở đâu?

Plugin không có màn hình thiết lập. Plugin sẽ tự động hoạt động sau khi kích hoạt.

Cách chặn lazy load hình ảnh hoặc iframe?

Bạn có thể thêm class skip-lazy để plugin bỏ qua lazy-load cho các hình ảnh hoặc iframe bạn muốn.

Plugin vẫn tải tệp JavaScript! Tôi không muốn điều đó.

This is perfectly fair. Note that the plugin only loads the JavaScript file as a fallback for when the user’s browser does not support the native loading attribute yet. The file includes logic to still autoload the image in a non-native way. If you prefer to purely rely on the loading attribute and not provide any fallback, you can easily disable it by adding a line add_filter( 'native_lazyload_fallback_script_enabled', '__return_false' ) somewhere in your site’s codebase.

Plugin hoạt động với AMP không?

Nếu bạn sử dụng AMP, bạn không cần nó, vì AMP đã tích hợp lazy-load. Tuy nhiên, plugin sẽ không gây lỗi tương tích với AMP.

Gửi yêu cầu hỗ trợ ở đâu?

Với yêu cầu hỗ trợ, hãy sử dụng diễn đàn hỗ trợ wordpress.org. Nếu bạn gặp lỗi kĩ thuật và bạn có hướng xử lí, bạn cũng có thể đăng ở Github.

Cách đóng góp cho plugin?

Nếu bạn có ý tưởng cải thiện plugin hoặc xử lí lỗi, hãy gửi lỗi hoặc gửi pull request tại Github. Nhớ xem hướng dẫn đóng góp.

Bạn cũng có thể đóng góp cho plugin bằng cách dịch. Chỉ cần truy cập translate.wordpress.org để bắt đầu.

Đánh giá

31 Tháng Mười Hai, 2020
This plugin adds loading="lazy" and then, the browser lazy loads the image. I think that native lazy loading performed by the browser is the only viable solution for lazy loading. For many years, I tried to implement lazy loading on my websites. I faced many issues. Once images were not crawled. Once my website was penalized because of cloaking. Versions differed depending on the client. I am enough with javascript scripts that slow down the pageload and negatively impact the pagespeed insight. I think that for now and in the future, the native lazy loading is the only way to go for lazy loading.
27 Tháng Hai, 2020
First, did not break my site and it did lazyload most of the page images. It does not lazyload images if they are served from a different host. Example, unbounce, etc. I will add another caveat, all of my images and their versions are always carefully resized and highly compressed. Checked with lighthouse and my score took a hit downwards. 13 points down on performance score. I tested on my Staging area, uncached. FCP went from 2.1s to 4.2s, all of the other metrics, including time to interactive, CPU idle, speed index and First Meaningful Paint took a dive. I will chuck this to I was already hyperoptimized and lazy loading is not truly needed on my site/s. But I would advise others to try it out (not on their live site) and test speed with Google Lighthouse before and after.
17 Tháng Hai, 2020
Seems to work well. On browsers that don't support lazy loading, it doesn't seem to load the images as soon as I would like. As in there can be a bit of a delay between scrolling and the image appearing on screen. Not to bad though. Not going to worry about it as native image loading is the way of the future and will be implemented into more browsers.
Đọc tất cả 31 đánh giá

Người đóng góp & Lập trình viên

“Native Lazyload” là mã nguồn mở. Những người sau đã đóng góp vào plugin này.

Những người đóng góp

“Native Lazyload” đã được dịch qua 16 ngôn ngữ. Cảm ơn những người tham gia dịch vì đóng góp của họ.

Dịch “Native Lazyload” sang ngôn ngữ của bạn.

Muốn tham gia phát triển?

Duyệt code, check out SVN repository, hoặc theo dõi nhật ký phát triển qua RSS.

Nhật ký thay đổi

1.0.2

  • Fix broken images which are using data URI scheme (e.g. base64-encoded images). Props ieim.
  • Fix images in IE 11 not being loaded until the user starts scrolling. Props Soean.
  • Fix image loading script not working in IE10 and other browsers that do not support dataset.

1.0.1

  • Improve compatibility with other plugins by using more specific class and only adding it for JS fallback.
  • Run lazy-load script on DOMContentLoaded when necessary to improve compatibility with plugins like Autoptimize.
  • Do not transform elements inside an AJAX response due to lack of predictability of the context and script execution.

1.0.0

  • Phát hành lần đầu