Compression refers to when files are optimized in a manner as to reduce the number of requests and bytes/request in order to reduce the time it takes to load them.
This is beneficial for latency as it enables webpage resources to be transferred & loaded at a faster, more efficient rate.
Compression can be applied to reducing the size of images, fonts & more.
Difference Between Lossy & Lossless Data Compression
When files are compressed, the code is manipulated in a way to be more compact, so that when transferred less data needs to be passed along, and then they can be decompressed when loaded by a client.
The two primary compression categories are Lossy & Lossless compression.
Lossy compression, much like it sounds, means compressing a file by removing unnecessary bits of information from it.
Files of all types from images to audio files contain things that are not necessary, which can be removed without sacrificing the overall quality.
Audio files contain noises that humans can’t hear & some images contain elements of detail in them that are too sharp for the human eye to notice.
Therefore, in lossy compression these elements are removed, in order to not sacrifice quality, while still reducing the transferred file size.
One downside is that too much lossy compression can impact the quality of the files & files that rely heavily on data may lose some of the entries & inputs in their datasets.
Lossless compression occurs when files are compressed by being reconfigured to remove any redundant bits of code.
Once these items are removed, the file can be compressed & when loaded can be completely reconfigured to its original state, as the redundant bits of code are still accounted for in the file.
Some examples of this include GZip files & PNG images.