HUSKY - Products Filter Professional for WooCommerce

パフォーマンス最適化:大規模なカテゴリ階層向けの遅延読み込みスライドアウト

親カテゴリがあり、次のような場合:

  • 大量の製品 (500-1000+)
  • ディープカテゴリ階層 (複数レベルのサブカテゴリ)
  • 動的再カウントが有効になりました

Product filter could generate hundreds of SQL queries ユーザーがフィルターを使用しなくても、すべてのページロード時に実行されます。これにより、次のようになります:

  • ページ読み込みが遅い(10秒以上)
  • 504 Gateway Timeoutエラー
  • 高いサーバー負荷
  • ユーザーエクスペリエンスが悪い

なぜこれが起こるのか

Dynamic Recount が有効な場合、WOOF は次のことを行う必要があります。

  1. すべての子カテゴリを再帰的に処理する
  2. 各タームの SQL クエリを実行して製品をカウントします
  3. 現在のカテゴリコンテキストを考慮してカウントを計算する

例: 「サングラス」カテゴリとサブカテゴリ(男性 → 女性 → ブランド → カテゴリ)は、大規模なクエリ負荷を発生させます。

従来のソリューション(不十分)

CSS/displayルールでスライドアウトを非表示にする – Filter still processes on server
動的再カウントの無効化 – 重要な機能が失われます
フィルターオプションの削除 – ユーザーは正しくフィルターできません
データベースインデックス – マイナーな改善ですが、根本原因を解決しません。

最適なソリューション:遅延読み込みスライドアウト

主要コンセプト: スライドアウトが開かれたときにのみフィルターを読み込みます。

✅ ページが即座に読み込まれます(フィルター処理なし)
✅ フィルターは必要に応じて完璧に機能します
✅ サーバーリソースの無駄なし
✅ ボットやカジュアルな閲覧者に最適
✅ Keeps all filter functionality intact

実装

次のコードをテーマに追加します functions.php:

/**
 * WOOF Lazy-Load Slideout Filter
 * Loads filter only when user clicks to open slideout
 * Solves performance issues with deep category hierarchies
 */
add_action('wp_footer', function () {
    // Only on product category pages (optional - remove condition to show everywhere)
    if (!is_product_category()) {
        //return;
    }
    ?>

    <!-- Slideout Trigger Button -->
    <div id="woof-slideout-trigger" style="position: fixed; right: 0; top: 50%; transform: translateY(-50%); z-index: 9999; cursor: pointer; background: #333; color: #fff; padding: 15px 10px; border-radius: 5px 0 0 5px; font-weight: bold; writing-mode: vertical-rl; text-orientation: mixed;">
        FILTERS
    </div>

    <!-- Slideout Panel -->
    <div id="woof-slideout-panel" style="position: fixed; right: -350px; top: 0; width: 350px; height: 100%; background: #fff; box-shadow: -2px 0 10px rgba(0,0,0,0.3); z-index: 9998; transition: right 0.3s ease; overflow-y: auto; padding: 20px;">
        
        <!-- Close Button -->
        <div style="text-align: right; margin-bottom: 15px;">
            <span id="woof-slideout-close" style="cursor: pointer; font-size: 24px; font-weight: bold;">✖</span>
        </div>

        <!-- WOOF Filter with autohide - loads only on first click -->
        <?php echo do_shortcode('[woof autohide=0 start_filtering_btn=1]'); ?>
    </div>

    <!-- Background Overlay -->
    <div id="woof-slideout-overlay" style="position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: rgba(0,0,0,0.5); z-index: 9997; display: none;"></div>

    <script>
        jQuery(document).ready(function ($) {
            var $trigger = $('#woof-slideout-trigger');
            var $panel = $('#woof-slideout-panel');
            var $overlay = $('#woof-slideout-overlay');
            var $close = $('#woof-slideout-close');
            var filterLoaded = false;

            // Open slideout
            $trigger.on('click', function () {
                $panel.css('right', '0');
                $overlay.fadeIn(300);

                // Auto-trigger WOOF "Start Filtering" button on first open
                if (!filterLoaded) {
                    setTimeout(function () {
                        var $woofBtn = $('.woof_start_filtering_btn');
                        if ($woofBtn.length) {
                            $woofBtn.trigger('click');
                            // Hide the button after triggering
                            $woofBtn.hide();
                            filterLoaded = true;
                        }
                    }, 500);
                }
            });

            // Close slideout
            function closeSlideout() {
                $panel.css('right', '-350px');
                $overlay.fadeOut(300);
            }

            $close.on('click', closeSlideout);
            $overlay.on('click', closeSlideout);
        });
    </script>

    <?php
}, 999);

設定手順

  1. 現在のスライドアウトを無効にする 有効になっている場合は、WOOF 設定で
  2. 上記のコードを追加しますfunctions.php アクティブなテーマの
  3. これらのWOOF設定を有効にしておいてください:
    • キャッシュ動的再カウント: はい
    • タームをキャッシュ: はい
    • 空のタームを非表示:はい
    • 動的再カウント:はい
  4. オプションのカスタマイズ:
    • スライドアウト幅を調整: 変更 width: 350px and right: -350px
    • ボタンの位置を変更:変更する top: 50%
    • 色をカスタマイズ: 更新 background and color
    • サイト全体で動作するようにする: を削除してください if (!is_product_category()) 条件

仕組み

  1. ページ読み込み: トリガーボタンのみが表示されます (フィルター処理なし)
  2. ユーザーがボタンをクリック: スライドアウトが開く、オーバーレイが表示される
  3. まず、次のものだけを開きます: JavaScriptが非表示の「フィルタリング開始」ボタンを自動的にクリックします。
  4. フィルターロード: WOOF はすべてのクエリを処理し、フィルターオプションを表示します
  5. 後続のオープン: フィルターはすでにロードされており、即座に開きます

実際の成果

前:

  • ページ読み込み: 10〜15秒 (または504タイムアウト)
  • 500以上のSQLクエリ/ページビュー
  • 高い直帰率

後:

  • ページ読み込み: 2 秒未満
  • フィルターは ~3 秒でロードされます (要求された場合のみ)。
  • サーバー負荷を約50%削減(多くのユーザーはフィルターを開きません)

互換性

✅ すべてのWOOFバージョンで動作します
✅ ページキャッシュと互換性があります (WP Rocket, LiteSpeed など)
✅ モバイルフレンドリー
✅ どのWordPressテーマでも動作します

高度なカスタマイズ

テーマのスタイルに合わせる:

/* Add to your theme's CSS */
#woof-slideout-trigger {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    font-family: 'Your Theme Font', sans-serif;
    letter-spacing: 2px;
}

#woof-slideout-panel {
    background: #f8f9fa;
    font-family: 'Your Theme Font', sans-serif;
}

#woof-slideout-trigger:hover {
    transform: translateY(-50%) scale(1.05);
}

左サイドスライドアウト:

これらの値を変更します:

right: -350px  →  left: -350px
right: 0       →  left: 0
right: -350px  →  left: -350px

このソリューションを使用するタイミング

次の場合に、スライドアウトの遅延読み込みを使用します:

  • カテゴリに階層が深い(3レベル以上)
  • カテゴリー内の500以上の製品
  • 動的再カウントが必要です
  • ページ読み込み時間 > 5秒
  • 504タイムアウトが発生しています。

サイドバーフィルターの代替

スライドアウトの代わりにサイドバーを好む場合は、次を使用してください:

echo do_shortcode('[woof autohide=1 start_filtering_btn=1]');

これにより、サイドバーに「フィルター開始」ボタンが作成され、クリックするとフィルターが読み込まれます。


このソリューションは、最高のバランスを提供します パフォーマンス and 機能、ユーザーが必要とする完全なフィルタリング機能を維持しながら、高速なページ読み込みを保証します。

参照: https://pluginus.net/support/topic/performance-issue-504-timeouts-on-parent-category-with-deep-hierarchy-flatsome-theme/