innocode-digital/wp-deferred-loading

延迟加载 JavaScript 和 CSS 文件。

安装次数: 12,522

依赖项: 2

建议者: 0

安全性: 0

星标: 0

关注者: 14

分支: 2

类型:wordpress-muplugin

1.4.1 2020-06-24 12:07 UTC

This package is auto-updated.

Last update: 2024-09-24 21:39:42 UTC


README

描述

WordPress 插件,用于延迟加载 JavaScript 和 CSS 文件。

安装

将此仓库克隆到 wp-content/plugins/

cd wp-content/plugins/
git clone git@github.com:innocode-digital/wp-deferred-loading.git

从插件页面激活 延迟加载 或使用 WP-CLIwp plugin activate wp-deferred-loading

您也可以将其作为 必用插件 安装。

使用方法

要延迟加载 JavaScript 文件,请将其添加到主题的 functions.php 文件中

add_filter( 'deferred_loading_scripts', function () {
    return [
        // List of enqueued scripts.
    ];
} );

add_filter( 'deferred_loading_scripts', function () {
    return '*'; // All enqueued scripts.
} );

要延迟加载 CSS 文件,请将其添加到主题的 functions.php 文件中

add_filter( 'deferred_loading_styles', function () {
    return [
        // List of enqueued styles.
    ];
} );