📜 ⬆️ ⬇️

Block client side caching

Recently, in heavily loaded sites, the use of Partial Caching or block caching has become increasingly common. This is achieved, as a rule, through the use of seemingly long forgotten, SSI or technologies close to it (for example, ESI ). For example, in bundles of Nginx + Memcached + SSI or Varnish + ESI.

Recently, a topic in which the author described this caching method also appeared on Habré.

In this topic in the 3rd version of the solution, the author invited the readers of the topic to bring their own solutions to this problem.
')
This topic is actually dedicated to this topic.

Formulation of the problem


In most cases, the web page consists of blocks. For example, for the simplest page, these are blocks: a header, a basement, a right or left block, and a block of main content. If the site is more complex, then, accordingly, there will be more such blocks, for example, for a habr these are the blocks: “last posts”, “last comments”, “similar posts”, etc. Accordingly, problems arise if we want to cache the page at the presentation level, i.e. directly generated html because to invalidate the cache for such a page would have to change any of the blocks located on this page.
Therefore, in most cases, caching is applied at the model or data level, which subsequently fill in a certain page template.

This is where SSI comes to the rescue, thanks to this technology, we actually break the page into these very logical blocks, and cache each block separately.

An example of a page using the SSI insert:
 <html> <body> <div class="header"> <!--# include virtual="/header.php" --> </div> <div class="main_content"> <!--# include virtual="/main.php" --> </div> <!--# include virtual="/footer.php" --> </body> </html> 
<html> <body> <div class="header"> <!--# include virtual="/header.php" --> </div> <div class="main_content"> <!--# include virtual="/main.php" --> </div> <!--# include virtual="/footer.php" --> </body> </html>

Here, it would seem, all is well, but there are several BUTs on which I would like to linger.

Problems




What is offered?


And the following caching mechanism is proposed:

Results




The disadvantages of this caching method can include problems with indexing, because some search engines' crawlers do not handle JavaScript

It will be interesting to hear your views on the approach and suggestions.

List of links


Source: https://habr.com/ru/post/96022/


All Articles