blackbird/external-resources-loader
最新稳定版本:1.0.6
Composer 安装命令:
composer require blackbird/external-resources-loader
包简介
Easily lazy load scripts and styles by url
README 文档
README
This tiny Magento 2 module will allow you to easily lazy load scripts and styles by url.
Installation
composer require blackbird/external-resources-loader
php bin/magento setup:upgrade
Usage
Load script :
blackbird.loadExternalResource('https://cdn.jsdelivr.net/npm/@splidejs/splide@4.1.4/dist/js/splide.min.js') .then(() => /* code which is executed after the lib has loaded */)
Load style :
blackbird.loadExternalResource('https://cdn.jsdelivr.net/npm/@splidejs/splide@4.1.4/dist/css/splide.min.css') .then(() => /* code which is executed after the style has loaded */)
Load multiple related scripts and styles :
Promise.all([ blackbird.loadExternalResource('https://cdn.jsdelivr.net/npm/@splidejs/splide@4.1.4/dist/js/splide.min.js'), blackbird.loadExternalResource('https://cdn.jsdelivr.net/npm/@splidejs/splide@4.1.4/dist/css/splide.min.css') ]).then(() => /* code which is executed after the style and the lib has loaded */)
Troubleshooting
The loadExternalResource method will load a script or a style depending on the url extension.
If the url doesn't end by .js or .css, you could lazy load resource using one of these 2 methods :
loadExternalScript: load resource from a url that provides javascript contentloadExternalStyle: load resource from a url that provides css content
For instance :
blackbird.loadExternalScript("<?= $block->getViewFileUrl('js/my-script') ?>")
统计信息
- 总下载量: 16.57k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 6
- 点击次数: 1
- 依赖项目数: 4
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2024-01-02