discolabs / cartjs

A Javascript library to power cart management for Shopify themes.
https://cartjs.org
MIT License
478 stars 85 forks source link

Avoid using cached request #185

Closed 8geonirt closed 4 years ago

8geonirt commented 4 years ago

Fixes #158

This commit adds a timestamp to the API call to get a non-cached response. This approach is done by Shopify itself to avoid loading cached assets image

Note: I am maintaining a Shopify theme and we have a custom slide cart component created from scratch (no libraries used), we faced the same issue and before creating a fix for this I found this library and I would like to contribute to it with that simple fix.

8geonirt commented 4 years ago

@gavinballard whenever you have a chance could you please take a look at it?

gavinballard commented 4 years ago

@8geonirt Released in 1.0.2.

8geonirt commented 4 years ago

@8geonirt Released in 1.0.2.

Awesome! Thanks for taking a look at it 👍

capatina commented 3 years ago

It seems this isn't working anymore and the cart.js endpoint is being cached regardless.

capatina commented 3 years ago

Another workaround:

$.ajax({ type: 'GET', url: '/cart.js', cache: false, dataType: 'json', success: function(cart) { CartJS.init(cart, { "moneyFormat": "{{ shop.money_format }}", "moneyWithCurrencyFormat": "{{ shop.money_with_currency_format }}", "requestBodyClass": "cart-loading" }); } });

gavinballard commented 3 years ago

Thanks @capatina. I have an underlying change to pass cache: false in the Ajax request, should be released shortly.