Lag when 'Add to cart' button is clicked for the first time.

I have my form which adds an item to the cart, and open the sidecart. The code is as below,
<form action="https://<FOXY_STORE_DOMAIN>/cart" method="post" accept-charset="utf-8">
<input type="hidden" name="category" value="Category 1">
<input type="hidden" name="price" value="100">
<input type="hidden" name="code" value="somecode">
<button class="btn-inner add-to-cart-btn" type="submit">
</button>
</form>
<script data-cfasync="false" src="//cdn.foxycart.com/<?php echo FOXY_STORE_NAME; ?>/loader.js" async defer></script>

When I click the submit button for the first time, it loads some resources from the foxycart backend and then shows the sidecart. So, there is a lag between the button click and the sidecart display. However, when the button is clicked the second time, there is no lag as the resources are loaded already.

Is there a way to preload all the resources for sidecart, to eliminate the lag? or is there any other way to remove the lag?

Thanks
Comments
  • image

    I get the following warning on browser console when submit button is clicked. Seems like the foxycart javascript file is making a synchronous XMLHttpRequest, thus adding a lag in UI.
  • fc_adamfc_adam FoxyCart Team
    @swastikroy1993,

    Thanks for posting to ask!

    When clicking the add to cart on your page, our javascript shouldn't be loading in any resources at that point. The action from a first click to a subsequent click should be pretty identical, it's just sending off the request to the cart to add that product.

    Our loader.js file does dynamically load in the javascript and css file on page load, and with how that file is included, it does mean that those files tend to load at the end of page load. This means that it does take a moment before our javascript initialises for the sidecart functionality to work. Interacting with an add to cart prior to that point though would load our full-page cart experience, instead of it delaying the normal sidecart interaction.

    Can you clarify what resources you're seeing being loaded on the first interaction with an add to cart? If you're able to, could you also share with us a link to your add to cart page so we can try to replicate that on our side too? If you'd prefer to keep it private, you can select the "whisper" checkbox when replying and enter my forum username in the text input that appears.
    I get the following warning on browser console when submit button is clicked. Seems like the foxycart javascript file is making a synchronous XMLHttpRequest, thus adding a lag in UI.
    Can I confirm with you what browser you saw that warning in, and what interaction on the page caused it to appear? I'm trying to trigger it on my own test store, but I'm not seeing that appear when interacting with an add to cart.
Sign In or Register to comment.