
內容簡介
使用WooCommerce可能會大幅耗盡伺服器資源並減慢網站加載。此外掛程式可以停止載入WooCommerce內不需要的額外項目並加速WordPress核心的admin-ajax.php檔案。
新增以下功能:
add_action( 'wp_enqueue_scripts', 'child_manage_woocommerce_styles', 99 );
function child_manage_woocommerce_styles() {
//移除產生器meta標籤
remove_action( 'wp_head', array( $GLOBALS['woocommerce'], 'generator' ) );
//首先檢查Woo是否存在以防止致命錯誤
if ( function_exists( 'is_woocommerce' ) ) {
//取消訂閱腳本和樣式
if ( ! is_woocommerce() && ! is_cart() && ! is_checkout() ) {
wp_dequeue_style( 'woocommerce_frontend_styles' );
wp_dequeue_style( 'woocommerce_fancybox_styles' );
wp_dequeue_style( 'woocommerce_chosen_styles' );
wp_dequeue_style( 'woocommerce_prettyPhoto_css' );
wp_dequeue_script( 'wc_price_slider' );
wp_dequeue_script( 'wc-single-product' );
wp_dequeue_script( 'wc-add-to-cart' );
wp_dequeue_script( 'wc-cart-fragments' );
wp_dequeue_script( 'wc-checkout' );
wp_dequeue_script( 'wc-add-to-cart-variation' );
wp_dequeue_script( 'wc-single-product' );
wp_dequeue_script( 'wc-cart' );
wp_dequeue_script( 'wc-chosen' );
wp_dequeue_script( 'woocommerce' );
wp_dequeue_script( 'prettyPhoto' );
wp_dequeue_script( 'prettyPhoto-init' );
wp_dequeue_script( 'jquery-blockui' );
wp_dequeue_script( 'jquery-placeholder' );
wp_dequeue_script( 'fancybox' );
wp_dequeue_script( 'jqueryui' );
}
}
}
如果你好奇以上功能到底是做什麼,我們可以更清楚地解釋其做法。重要的是要了解安裝的插件功能。
此插件會指示WP,除非用戶位於WooCommerce頁面上,否則不要載入大量的WooCommerce腳本。這樣網站的非WooCommerce頁面肯定會載入得更快,因為許多這些WooCommerce腳本會在每個頁面上載入。使用此插件可節省商店內存,因此WooCommerce頁面也會更快。
總之,此插件可以在非WooCommerce頁面上關閉重度腳本,這對於行銷網站很有價值,因為如果你行銷網站時會有一個部落格,這些頁面將會被索引並帶動流量到產品上。在大多數電子商務網站中,幾乎所有訪問者都會降落在非WooCommerce頁面上。
沒有比這更簡單或更快速地加速WooCommerce網站的方法了。
外掛標籤
開發者團隊
原文外掛簡介
WooCommerce is powerful but it loads dozens of scripts and styles even when they are re not needed, which can slow your site down.
This plugin gives you an instant performance boost by letting you disable unnecessary WooCommerce frontend assets on non WooCommerce pages.
Features
– One-click toggles for each WooCommerce asset JS and CSS
– Grouped by functionality: Core Scripts, Cart, Block Styles, General Styles
– Savings Test Tool per URL
– Custom WooCommerce handle entry for global disable
– Front end WooCommerce Assets menu
– Per page list of script assets loading with disable option
– Per page list of style assets loading with disable option
– Meta box for custom handle input per page disable rules
– Select All and Deselect All buttons to quickly apply optimizations
By reducing what loads on non-commerce pages, your site becomes leaner and faster especially for blog, landing, or informational pages.
How It Works
Only WooCommerce pages (like shop, cart, checkout, and product pages) truly need WooCommerce assets.
So this plugin:
– Lets you turn off WooCommerce assets on non-WooCommerce pages
– Automatically preserves functionality where needed (e.g. checkout/cart)
– Saves bandwidth, server load, and improves core Web Vitals
There’s no need to write any code or modify theme files.
