The wc-ajax=get_refreshed_fragments request in WooCommerce is responsible for updating the cart dynamically using AJAX. However, it can slow down page load times due to frequent AJAX requests, especially on high-traffic sites.
By default, WooCommerce triggers AJAX cart updates on every page. To prevent 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 disables AJAX cart fragments on all pages except cart & checkout.
Reduces unnecessary server load & improves page speed.
WooCommerce checks the cart on every page load. To limit this:
add_filter('woocommerce_cart_hash', function($hash) {
if (!is_cart() && !is_checkout()) {
return false; // Prevent unnecessary AJAX calls
}
return $hash;
});
This prevents WooCommerce from triggering AJAX cart updates when the cart hasn't changed.
Instead of disabling AJAX, you can cache responses to avoid frequent server hits.
Add this to your Nginx configuration:
location ~* wc-ajax=get_refreshed_fragments {
expires 30m;
add_header Cache-Control "public, max-age=1800";
}
This caches AJAX responses for 30 minutes, reducing load time.
<IfModule mod_expires.c>
ExpiresByType application/json "access plus 30 minutes"
</IfModule>
This reduces repeated AJAX requests by caching responses.
WooCommerce stores cart data in the database, which slows down AJAX requests.
For Redis Caching:
sudo apt install redis-serverdefine('WP_CACHE', true);
define('WP_REDIS_HOST', '127.0.0.1');sudo systemctl restart redisThis speeds up WooCommerce AJAX calls by caching cart data.
| Issue | Fix |
|---|---|
| AJAX calls on all pages | Disable with wp_dequeue_script('wc-cart-fragments') |
| Frequent cart updates | Reduce frequency with woocommerce_cart_hash filter |
| High server load from AJAX requests | Cache responses using Nginx or Apache |
| Slow database queries | Enable Redis or Memcached caching |
Now WooCommerce loads faster, and AJAX requests are optimized!