Compression optimization
Compression & Optimization Deep Dive¶
Overview¶
Compression (gzip, brotli) reduces bandwidth.
Core Concepts¶
- Accept-Encoding request header
- Content-Encoding response header
- OkHttp handles automatically
- Saves ~60-80% bandwidth
Code Examples¶
// Already transparent in OkHttp
val httpClient = OkHttpClient.Builder()
.addNetworkInterceptor { chain ->
val response = chain.proceed(chain.request())
// OkHttp automatically decompresses
response
}
.build()
Senior-Level Insights¶
- Compression trade-off: CPU vs bandwidth
- For images: compress beforehand (WebP, HEIC)
- Disable for pre-compressed (videos)