3

I have a problem with countdown timer in Magento 2 when Page Cache is enabled.

On page load the timer always start from the same time: e.g. 19:05:00 It's refreshed once if cache is flushed.

I have tried to use tag "cacheable="false" - but this disable FPC on page at all (the page load become too long).

I have also try to use $this->_isScopePrivate = true; in my block class, but this not help, such as timer depend on category attribute. (it use registry('category'))

Can anybody help with this?

asked May 20, 2016 at 13:55
1
  • Why do you not use js for timer? Commented May 20, 2016 at 14:22

1 Answer 1

3

Magento 2 FPC does not support hole punching. (It's not good for performance anyway.) You will have to implement the feature in JavaScript, using JS variables, cookies, local storage, or AJAX requests to handle any state or additional information you need.

This technique is how private or customer-specific data is handled across the entire Magento core in 2.0+. For example, go to your account dashboard, orders, address book, cart, or checkout, and note how the page contents all fill in after load: They aren't part of the page that's cached in FPC, they're filled in by JS after the page loads.

If you're counting down, maybe store the completion date and time on the page, then use JS to calculate how much time is left until then.

answered May 20, 2016 at 14:57

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.