innocode-digital/wp-hybrid-lazy-loading
Composer 安装命令:
composer require innocode-digital/wp-hybrid-lazy-loading
包简介
A Progressive Migration To Native Lazy Loading.
README 文档
README
Description
A Progressive Migration To Native Lazy Loading.
The idea of plugin is to use Native Lazy Loading when browser supports it and for all others implements lazy loading through lazysizes library that loads only when needed.
Plugin adds loading attribute for all attachments, oEmbed iframes, images and iframes that are inserted to content through editor, also CSS class lazyload adds to those elements as well as data-src, data-srcset and data-sizes are created from corresponding attributes.
Installation
Clone this repo to wp-content/plugins/:
cd wp-content/plugins/
git clone git@github.com:innocode-digital/wp-hybrid-lazy-loading.git
or use Composer for that.
Activate Hybrid Lazy Loading from Plugins page
or WP-CLI: wp plugin activate wp-hybrid-lazy-loading.
Documentation
By default plugin loads lazysizes lazily, which means only for ones that are w/o Native Lazy Loading support but it's possible to change this behaviour with filter:
add_filter( 'innocode_wp_hybrid_lazy_loading_lazy_enqueue_lazysizes', '__return_false' ); // Default is "true"
It makes sense when e.g. lazysizes is using also for other functionality.
By default CSS class "lazyload" removes from elements in browsers with Native Lazy Loading support but it's possible to change this behaviour with filter:
add_filter( 'innocode_wp_hybrid_lazy_loading_force_use_lazysizes', '__return_true' ); // Default is "false"
It makes sense when e.g. it's needed to use lazysizes CSS classes that are adding to element during loading process in all browsers.
By default all attachments are loading lazily but it's possible to change this behaviour with filter:
add_filter( 'innocode_wp_hybrid_lazy_loading_attachment_loading', function ( $type, $attachment_id ) {
$type = 'eager'; // Default is "lazy"
return $type;
}, 10, 2 );
It makes sense when e.g. featured image should be loaded immediately.
If there are images and iframes that are rendered in PHP code of theme or plugin and they should be loaded lazily, it's possible to use next methods:
/**
* Adds "loading" attribute and "lazyload" CSS class to images in HTML code
*
* @param string $html
* @return string
*/
\Innocode\WPHybridLazyLoading\DOM::images( $html );
/**
* Adds "loading" attribute and "lazyload" CSS class to iframes in HTML code
*
* @param string $html
* @return string
*/
\Innocode\WPHybridLazyLoading\DOM::iframes( $html );
/**
* Adds "loading" attribute and "lazyload" CSS class to elements in HTML code by tag
*
* @param string $tag
* @param string $html
* @return string
*/
\Innocode\WPHybridLazyLoading\DOM::elements( $tag, $html );
innocode-digital/wp-hybrid-lazy-loading 适用场景与选型建议
innocode-digital/wp-hybrid-lazy-loading 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 1.76k 次下载、GitHub Stars 达 0, 最近一次更新时间为 2019 年 11 月 06 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 innocode-digital/wp-hybrid-lazy-loading 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 innocode-digital/wp-hybrid-lazy-loading 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 1.76k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 12
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: GPL-2.0-or-later
- 更新时间: 2019-11-06