Web performance
How to make a website faster and how to tell that it really is fast: measuring and Core Web Vitals, images, browser cache, loading CSS, JavaScript and fonts, compression and data transfer and finally speed on the server – PHP and the database. The examples are verified in PHP 7.4 to 8.5, on the Apache server and in the Chrome, Firefox and Safari browsers (the WebKit engine).
Website speed is not measured by a single number. Google evaluates it with three Core Web Vitals metrics – LCP, INP and CLS. What they mean, which values are good, how to measure them and how to collect them from real visitors into your own database.
Images are often the largest part of a page and often also the element by which LCP is measured. How to choose a format, send every device an image of the right size, defer loading images outside the screen and prevent the content from jumping around.
The fastest file is the one that does not have to be downloaded at all. How to tell the browser with the Cache-Control header what it may store and for how long, how validation with ETag and the 304 response works and how to make sure that visitors get the new CSS and JavaScript after a change to the site.
The browser does not start rendering the page until it has the styles, and an ordinary script in the head even stops reading the HTML. How to load CSS and JavaScript so that they do not slow down the first display, what preload and preconnect are for, how to keep fonts from delaying the text and how not to slow down the responses of the page.
Text files – HTML, CSS, JavaScript, JSON and SVG – can be shrunk to a fraction of their size during transfer. How to turn on gzip and Brotli compression on Apache and in PHP, how to check it and what HTTP/2 and HTTP/3 bring.
Before the browser gets the first byte of the page, the server has to run PHP, ask the database and put the HTML together. How to measure where the time is lost, how OPcache helps, how to find slow queries and when to store the finished output in a cache.