N
N
Nikolai Egorov2018-10-31 14:13:31
symfony
Nikolai Egorov, 2018-10-31 14:13:31

How to make dynamic loading of static content on the page?

Hello!
I am almost finishing the transfer of the existing site from my "bike" to Symfony 4. And the site has blocks that are loaded by Ajax. And if these blocks were somehow generated or stored in the database, then they definitely need to be loaded by referring to some kind of controller that would return them. But most of them, 3 out of 4, are static and do not change. It turns out that for the sake of loading these static blocks, 3-4 processes will be launched each time with the launch of Symphony on the server.
I understand that the question has little to do with Symphony itself, rather a general one, relating to any CMS or framework. But I use Symphony, and it seems to be "heavier" than other brothers in terms of resource intensity.
Are there any features or tricks of working with Symphony in such situations? And in general, not only with Symphony, but with any other engines... Share your experience, please!
Thank you!
UPDATE: I forgot to add that I can't immediately insert this static content into the page, because it is repeated from page to page. And in order to improve search engine optimization, these pieces have to be inserted with Ajax after the page is loaded into the browser.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
voronkovich, 2018-10-31
@voronkovich

If the content is static, you can simply paste its HTML into the template. Otherwise, it's better to use HMVC: How to Embed Controllers in a Template
In the demo application, there are two examples illustrating the insertion of blocks with content: https://github.com/symfony/demo/blob/bbe5180a8c3b6... and https:// github.com/symfony/demo/blob/bbe5180a8c3b6...
The last example also uses ESI to cache the block.
Also, if the block is static, then you can not create a separate controller for it, but use the TemplateController: How to Render a Template without a custom Controller

G
GTRxShock, 2018-10-31
@GTRxShock

But I use Symphony, and it seems to be "heavier" in terms of resource consumption than the other brothers

a controversial statement, especially towards version 4, since it uses a flex approach with an add-on over a micro-kernel
something that is statically reasonable to give immediately when rendering the page
do not exaggerate, since the bootstrap framework is not a limiting process, if it is so critical, it is better to look towards compiled languages,
and ajax requests often return data in json format, without overhead + you can cache at the server level
ps if you run into iron from profitable traffic, this is a good sign, it means there will be enough money for a new one or refactoring :D

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question