XHR requests every second

Topic summary

Constant XHR (AJAX) requests to /cart.js every second were traced to analytics code that polls the cart and fires Facebook Pixel events. The code uses setInterval(…, 1000) to GET /cart.js (Shopify’s cart JSON endpoint) and, on item count increases, sends AddToCart events via orfbq to configured pixels.

Identified source: an Orichi-related Shopify app; the site owner confirms the Facebook Pixels Conversion API app is installed. The code references orichiCartItemCount and window.pixels, matching that app’s behavior.

Explanation and impact:

  • Purpose: track add-to-cart conversions reliably by polling the cart.
  • Performance: requests are small and generally negligible.

Options to address:

  • Accept the minor overhead as expected behavior for conversion tracking.
  • For optimization, integrate the app with the theme’s cart logic so requests fire only when the cart changes (instead of continuous polling).

Artifacts central to understanding: the provided JavaScript snippet is key; the screenshot is not essential.

Status: Resolved. Cause identified and confirmed; optional optimization noted, no mandatory fix required.

Summarized with AI on February 23. AI used: gpt-5.

Hi @Alex2094

I’m not entirely sure what’s causing it. Have you had any custom work done on the site - or just installed apps?

It’s this bit of code that’s causing the call:

var orichiCartItemCount = -1;
setInterval(function() {
    if (window.pixels != undefined && window.pixels.length > 0) {
        //debugger;
        $.ajax({
            type: 'GET',
            url: '/cart.js',
            dataType: 'json'
        }).done(cart => {
            if (cart.item_count > 0 && orichiCartItemCount != -1 && cart.item_count > orichiCartItemCount) {
                //debugger;       
                var lastItem = cart.items[0];
                let event_id = (new Date()).getTime() + getRandomInt(1, 100000);
                window.pixels.forEach(function(pixel, index) {
                    let pixelID = pixel.FacebookPixel;
                    orfbq(`${pixelID}`, 'AddToCart', {
                        content_ids: lastItem['product_id'],
                        content_type: 'product_group',
                        value: parseInt(cart.total_price) / 100,
                        content_name: lastItem['product_title'],
                        currency: currency,
                    }, event_id, pixel);
                })
            };
            orichiCartItemCount = cart.item_count;
        }).fail(function(jqXHR, textStatus) {
            orichiCartItemCount = -1;
        });
    }

}, 1000);

A quick search on “Orichi Shopify” shows these apps:

https://apps.shopify.com/partners/orichi

Do you have either of those installed?

1 Like