The speed of website and applications is considerably determined by latency and network itself. When it comes to content delivery, you just can't ignore the laws of physics – distance between end use and server plays a great role. The more data needs to travel, the more latency is. Luckily, there are ways to decrease it. Here are some tips for latency optimization.
What is latency?
First, we need to define what latency is. This is the time (usually measured in milliseconds) that a request goes from sender to receiver and is being processed, e.g. the trip time from browser to server. This variable greatly depends on the physical distance between the end user and the server, and network quality. Other things that affect latency are propagation, routers and storage delays.
How it can be measured?
There are three ways to define latency. Ping helps to find out delay time of how long the data is transferred in the Net and back to the user. Faster ping is better, it means that connection is stable and quick. Traceroute indicates the time of each hop while data is routed to its destination. MTR is the combination of both, and provides a detailed report that shows percentage of loss, average latency, etc.
Ways of Latency Optimization
You can’t eliminate latency entirely, but there are methods to control it. What can help?
- CDN services is technique that has the greatest effect. Caching the content on edge servers located in different places, it reduces the distance between the server and the end user. CDN solution is especially important for those whose customers access the site from different cities and countries.
- HTTP/2 decreases latency by minimizing round trips between sender and receiver with the help of parallelized transfers. But this function is supported by sites that run HTTPS.
- Keep the number of external HTTP requests as low as possible. If you link to the third party resources, they should work on fast infrastructure.
- Browser caching reduces latency dramatically, because this way the browser does not have to make additional request to the server.
- CDN prefetching is needed to make DNS lookups on a page on the background while user is surfing the site.
- Preconnect is setting up of early connections before HTTP request is sent to the server.
There are many ways of latency optimization that can reduce this variable several times, no matter where the users are located.