We're using Varnish as Page Cache, but we need to make a Ajax-Request on every page view to load the dynamic Stuff. In our case it's:

  1. global messages
  2. mini Cart
  3. form key

We reduced the amount of ajax request on a page by merging everything to a single ajax request, but my hope would be to avoid any hit on Magento for a varnish cached Page. I have some ideas to accomplish this and hope someone has already experience and give me some tips.

My Ideas for:

Global Messages

Rewrite the Core and save a serialized object with the messages in a cookie. With JS I'am able to read the cookie and render the messages.

Mini Cart

quite the same like my idea for global messages. If there is a change in the quote, I save a serialized object with all needed data in a cookie and render the cart with JS. The problem I see is, that the Object could be bigger then the allowed cookie size of ~4000 bytes. A solution could be to reduce the size of displayed products in the mini cart.
The second problem I see is to have the same expire date for the custom cookie and the frontend cookie.


actually I have no idea to solve this, but maybe there is no solution,

Problems I have with ESI:
There are still Magento hits and if I get it right, the page load is slower, because the request have to wait for the ESI Block. But maybe it could be a solution for the form_keys and the global messages, because the rendering ist quite fast.
Another reason I try to avoid ESI for the mini cart is, we do a lot of stuff in the card like adding free products and do custom price calculations. It took on average 150ms to render the mini cart.

I have read more about ESI and I actually don't see the benefit. Technically its the same like a ajax request. In Magento you have to create a controller to return the HTML of the block and include it in your template. Varnish call this URL exactly the same like a user would do. For that reason you have to pass the Varnish cache for this URL and you have a Cache MISS for that URL

1 Answer 1


try to have a look into Varnish ESI. To use The Formkey is kind of tricky. I suggest you to fetch them via ajax when you need it and replace it in all forms. In an Observer before the controller is loaded you can inject the formkey back into the Session. I can not post all the code here its way to much. But maybe it helps.

  • I actually don't see the benefit of ESI. I wrote my research in my post.
    – Pawel
    Sep 29, 2016 at 17:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.