I'm having problems with caching a block in Magento 2. The theme I'm using is getting content from the block via an AJAX call.
Is it possible how to cache such block in M2?
Thank you, Mateusz
2 Answers 2
Assuming you rely on jQuery, add cache: true as the ajax call option.
This flag will instruct $.ajax() not to add the parameter which you mentioned in the comment.
Every block in magento2 is by default cacheable. You can disable cacheing of that block by explicitly adding cacheable="false" as the block attribute. Can you make sure that this attribute is not added anywhere for this particular block
-
The block itself is stored in cache, but the problem lies in something else. Everytime the block loads, there is an AJAX call made to
/productfiler/index/firstloadwith some parameters. This loads the content of the block and this content is not cached and I need it to be.Do you have any ideas how to change that behaviour?Mateusz Serotiuk– Mateusz Serotiuk2017年05月17日 06:42:07 +00:00Commented May 17, 2017 at 6:42 -
1Either you can stop ajax loading the content and include that content in your block by coping all block information from productfiler_index_firstload to your block that is being cached. Or If you want to keep the ajax call then make sure that all blocks in productfiler_index_firstload.xml are cacheable. That means no block in there can have cacheable false attribute. We can be more helpful if you can provide both xmlsAbhishek Jakhotiya– Abhishek Jakhotiya2017年05月17日 07:15:04 +00:00Commented May 17, 2017 at 7:15
-
Thanks. The problem is, it's a widget that is placed in a CMS Block and this widget is actually making the AJAX call. And even worse, everything seems to be cached when I look at the code, the AJAX calls are still being made. How would you deal with that?Mateusz Serotiuk– Mateusz Serotiuk2017年05月17日 07:42:04 +00:00Commented May 17, 2017 at 7:42
Explore related questions
See similar questions with these tags.