The wc-ajax=get_refreshed_fragments request in WooCommerce is responsible for updating the cart contents dynamically using AJAX. However, it can slow down your website due to frequent requests and high server load.
By default, WooCommerce uses wc-ajax=get_refreshed_fragments to update the cart, even when it's not needed.
Add this to your theme's functions.php file:
add_action( 'wp_enqueue_scripts', function() {
if (is_front_page() || is_home()) {
wp_dequeue_script('wc-cart-fragments');
wp_deregister_script('wc-cart-fragments');
}
}, 11);
This removes unnecessary AJAX requests on the homepage, reducing load times.
If your site doesn't need cart updates outside the cart and checkout pages, use this:
add_action( 'wp_enqueue_scripts', function() {
if (!is_cart() && !is_checkout()) {
wp_dequeue_script('wc-cart-fragments');
wp_deregister_script('wc-cart-fragments');
}
}, 11);
This removes cart fragments everywhere except cart & checkout.
By default, WooCommerce triggers AJAX on every page load. To reduce this:
add_filter('woocommerce_cart_hash', function($hash) {
if (is_front_page() || is_home()) {
return false;
}
return $hash;
});
This prevents unnecessary AJAX calls when the cart hasn't changed.
If you cannot disable AJAX requests, you can cache them.
For Nginx, add:
location ~* wc-ajax=get_refreshed_fragments {
expires 30m;
add_header Cache-Control "public, max-age=1800";
}
For Apache, add to .htaccess:
<IfModule mod_expires.c>
ExpiresByType application/json "access plus 30 minutes"
</IfModule>
This caches the response, reducing repeated AJAX calls.
Use Redis or Memcached for caching WooCommerce sessions:
sudo apt install redis-server
Enable Redis in wp-config.php:
define('WP_CACHE', true);
define('WP_REDIS_HOST', '127.0.0.1');
| Issue | Fix |
|---|---|
| wc-ajax=get_refreshed_fragments slows down site | Disable on non-cart pages (wp_dequeue_script) |
| High server load from AJAX requests | Cache responses with Nginx/Apache |
| Too many AJAX requests | Reduce AJAX frequency with woocommerce_cart_hash filter |
| WooCommerce running slow | Use Redis/Memcached caching |
Now WooCommerce should load much faster!