Khắc phục WC-AJAX = GET_REFRESHED_FRAGMENT CPU sử dụng cao (vô hiệu hóa các đoạn giỏ hàng AJAX)

Một vấn đề khá phổ biến trên các cửa hàng trực tuyến với WooC Commerce là bộ xử lý tải quá mức với các yêu cầu AJAX của giỏ hàng. Fix wc-ajax = get_refreshed_fragments High CPU Usage.

Việc tải quá mức các tiến trình CPU bằng bất kỳ tập lệnh hiện tại nào cũng không có tác dụng gì ngoài việc giảm tốc độ tải của các trang cửa hàng trực tuyến, để mang lại điểm SEO và trải nghiệm người dùng thấp. Ít đơn đặt hàng hơn trên trang web.

Truy vấn wc-ajax = get_refreshed_fragments là gì và được sử dụng để làm gì

Để mọi người hiểu rõ hơn, với sự trợ giúp của tập lệnh AJAX này, WooC Commerce cho phép thêm sản phẩm vào giỏ hàng và cập nhật giỏ hàng mà không làm mới trang web. Giỏ hàng sẽ giao tiếp không đồng bộ với máy chủ lưu trữ thông qua AJAX (JavaScript và XML không đồng bộ).

Fix wc-ajax = get_refreshed_fragments  High CPU Usage
AJAX Add to Cart

In mod prestabilit, /?wc-ajax=get_refreshed_fragments este prezent in toate paginile site-ului pentru a urmari actiunile Add to Cart ale utilizatorului si schimbarile care pot sa apara in widget-ul cosului de cumparaturi. Aceste actiuni sunt cele care pun procese pe CPU si incetinesc viteza de incarcare a paginilor web. Uneori cu 4-5 secunde, ceea ce este foarte mult.

Khắc phục WC-AJAX = GET_REFRESHED_FRAGMENT CPU sử dụng cao (vô hiệu hóa các đoạn giỏ hàng AJAX)

Daca nu folositi un widget dinamic al cosului de cumparaturi in header sau intr-o alta zona permanenta a magazinului, cel mai indicat este sa renuntati la actualizarea dinamica si la urmarirea actiunilor de adaugare / actualizare cos.

Puteti dezactiva AJAX Cart Fragments pe paginile de arhive si sa redirectionati utilizatorii direct catre cosul de cumparaturi atunci cand un produs este adaugat in cos.

WooCommerce → Settings → Products.

Tắt Thêm vào giỏ hàng AJAX
Tắt Thêm vào giỏ hàng AJAX

Nếu bạn muốn kích hoạt tập lệnh này “Add to Cart Ajax“, nhưng không chạy trên trang đầu tiên của cửa hàng, hãy chỉnh sửa tệp tin.php của chủ đề hiện tại và thêm mã sau:

add_action ('wp_enqueue_scripts', 'dequeue_woocommerce_cart_fragments', 11);
function dequeue_woocommerce_cart_fragments () {if (is_front_page ()) wp_dequeue_script ('wc-cart-fragments'); }

Trong trường hợp, ngoài các trang WooC Commerce, bạn còn có một blog hoặc các trang tùy chỉnh khác không có sản phẩm nào, một ý tưởng hay là vô hiệu hóa các đoạn khỏi chúng.

add_action ('wp_enqueue_scripts', 'dequeue_woocommerce_cart_fragments', 11);
function dequeue_woocommerce_cart_fragments () {
if (is_front_page () || is_single ()) wp_dequeue_script ('wc-cart-fragments');
}

Tổng số vô hiệu hóa và fix wc-ajax = get_refreshed_fragments High CPU Usage (Disable AJAX Cart Fragments) nó được thực hiện với đoạn mã sau:

add_action ('wp_enqueue_scripts', 'dequeue_woocommerce_styles_scripts', 99);
function dequeue_woocommerce_styles_scripts () {
if (function_exists ('is_woocommerce')) {
if (! is_woocommerce () &&! is_cart () &&! is_account_page () &&! is_checkout ()) {
# Styles
wp_dequeue_style ('woocommerce-general');
wp_dequeue_style ('woocommerce-layout');
wp_dequeue_style ('woocommerce-smallscreen');
wp_dequeue_style ('woocommerce_frontend_styles');
wp_dequeue_style ('woocommerce_fancybox_styles');
wp_dequeue_style ('woocommerce_chosen_styles');
wp_dequeue_style ('woocommerce_prettyPhoto_css');
# Scripts
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');
}
}
}

Sau khi chọn một trong các phương pháp này (đặc biệt là phương pháp cuối cùng), bạn sẽ ngay lập tức nhận thấy tốc độ tải của cửa hàng trực tuyến tăng lên và mức tiêu thụ tài nguyên trên mỗi bộ xử lý (CPU) thấp hơn nhiều.

Đam mê về công nghệ, tôi viết với niềm vui trên sthealthsetts.com bắt đầu từ năm 2006. Tôi có trải nghiệm phong phú trong các hệ điều hành: MacOS, Windows và Linux, nhưng cũng trong các ngôn ngữ lập trình và nền tảng blog (WordPress) và cho các cửa hàng trực tuyến (WooC Commerce, Magento, Presashop).

Trang chủ Nguồn hướng dẫn của nó, các mẹo và tin tức hữu ích. Khắc phục wc-ajax = get_refreshed_fragments Mức sử dụng CPU cao (Vô hiệu hóa phân đoạn giỏ hàng AJAX)
Để lại một bình luận