How to improve your website performance with ESI
Performance of modern websites is getting more important than ever. They should be accessible on every device within no time – even on a smartphone with a low connection speed. The combination of functionality, usability and design is growing to a large and complex code base which forces Web Developers to cache each page as long as possible.
Assume a page with static content that doesn't change for months but at the top of the page the current weather is being displayed. The page will be cached for at least some hours but the temperature should update each 90 minutes – with the power of ESI (Edge Side Includes) this is no problem anymore and done with ease.
In this short example I'll show you the minimal code you need for a web project with Sulu.
Step 1 – enable ESI
First, you need to check your configuration - if you want to use ESI, it must be enabled.
Step 2 – set the controller
The next step is a new controller that fetches the data and returns the HTML. Lets name it WeatherController.
Step 3 – find the right position
Now there's only one thing left to do. In the twig template with the static content the ESI part must be included at the right position.
That's all you need to do.
Benefit from the full potential
There are many more use cases like a news ticker and other weather relevant information – like snow height or the status of a skiing lift.
For more detailed information regarding HTTP Cache and render ESI, head over to the official Symfony documentation