I
I
I'm Yoda2017-10-22 16:28:24
PHP
I'm Yoda, 2017-10-22 16:28:24

How to force Bitrix not to cache certain parts of the code in the template?

Hello connoisseurs!
Who faced such game as caching in Bitrix? The essence of the question is that it is necessary to exclude a section of code from caching (a device definition condition). I use this library device.js , only it with a probability of 99% correctly detects devices. In my opinion! The essence of the question is that through ajax I write the device type to the session. Next, in the component template, I set the condition

if ($device == "mobile") {
     $content = "content-mobile";
} else {
     $content = "content-desktop";
}

and so on according to the pattern of conditions, conditions ... Everything works great as long as it is possible to reset the cache. How can I disable caching of conditions or xs how else can I get around this? Where to dig it is necessary to get rid of it? Searches on the Internet did not bring much success, so I would be glad to help! Thank you!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Andrey Nikolaev, 2017-10-23
@gromdron

Forgive me, of course, but the game in this case is what you offer. Not a single framework supports "not caching a certain area inside the cached one" (if you find a refutation - we will be happy to talk and consider how this algorithm can be used).
Actually, Bitrix has 2 mechanisms for solving your case:
1) Remove caching of the result (html) and make data caching.
In my opinion, not the best option, since rendering also requires resources that are already expensive
2) Define an additional caching key.
In StartResulCache, you can add your own keys to parameter 2, and in this case you will have the key of the user's device (mobile / desktop), after which 2 caches will be stored: for mobile and for desktop clients.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question