Developer forum

Forum » Development » Cart looks empty on back button click

Cart looks empty on back button click

Christian Hansen Nørgaard
Reply

Hiya.

Does anyone have a solution to the cart looking empty when you click the browsers back button? I've already checked "Keep cart in context after checkout step" but this did'nt help. Solution is running 8.8.1.23.


Replies

 
Nicolai Pedersen
Reply

Hi Christian

I think we need to see it on the site to tell you why that happens...

BR Nicolai

 
Christian Hansen Nørgaard
Reply

http://www.feen-froen.dk/

1. Select a product

2. Add it to the cart

3. Click the browser back button (maybe twice if using chrome)

 
Nicolai Pedersen
Reply
This post has been marked as an answer

Ah, you mean the mini cart.

Problem is, that clicking back will load the page from browser history and since there was no products in the cart at that time, it says 0.

I can think of 2 ways to solve this.

  1. Easy fix is to send out a header so that the browser will not use cache when navigating back - but will load a new page. That is a setting in MC - see dump#1. Downside is of course that navigating back will be a little slower since the page will reload - it could also mean that you loose your scroll position (not sure about that)
  2. Another solution would be to load the mini cart using ajax and rendering the cart on a hidden page in json. When clicking back, the JS will fire and load the cart again - so the actual page is loaded from browser cache, but the minicart is re-loaded from the json feed. Downside is the additonal requests on all pages.

Hope this can help on the issue.

BR Nicolai

Capture.PNG
Votes for this answer: 1
 
Christian Hansen Nørgaard
Reply

Thanks for your answer Nicolai. I will try your solutions. :)

 

You must be logged in to post in the forum