Network efficiency
Skill almasumdev/awesome-mobile-performance-agent-skills/.github/skills/network/network-efficiency
Cut mobile network cost with HTTP/2, HTTP/3 (QUIC), Brotli/Zstd compression, and payload trimming. Use when p95 latency or bytes-per-screen exceeds budget.From its SKILL.md
npx -y skills add almasumdev/awesome-mobile-performance-agent-skills --skill network-efficiencyAssembled from the repository path, not quoted from the project. Check it against their README if it does not work.
2 things to look at
- no licenseNo license file was found in the repository. Code published without one is not open source by default, so using it at work is a question for whoever answers licensing questions where you are.
- 1 stars1 stars. Stars are a popularity signal and not a quality one, but at this level it is likely that nobody has read this closely except its author, and you would be relying on your own review.
SKILL.md
5.5 KB, ~1.4k tokens by cl100k_base, as published. Nobody here has run it
Network Efficiency
Instructions
Mobile networks are slow, lossy, and expensive. Every request pays connection setup, every byte pays radio time. Getting network efficiency right is often the single biggest perf win.
1. Budgets
| Metric | Budget (p95) |
|---|---|
| Bytes per screen | ≤ 150 KB (excl. images) |
| Image bytes per screen | ≤ 500 KB |
| Time-to-first-byte | ≤ 400 ms (4G) |
| Requests per screen | ≤ 8 |
2. Use HTTP/2 and HTTP/3
HTTP/1.1 means one in-flight request per connection; six connections to the same host become the ceiling. HTTP/2 multiplexes; HTTP/3 (QUIC over UDP) survives IP changes — critical on mobile as users move between Wi-Fi and cellular.
- Ensure your CDN advertises HTTP/3 via Alt-Svc.
- Android: OkHttp supports HTTP/2 by default; HTTP/3 via Cronet or
okhttp-3-quic(experimental). - iOS:
URLSessionuses HTTP/3 when server advertises it (iOS 15+). - RN: use
fetchbacked by URLSession/OkHttp — HTTP/2 is transparent. Considerreact-native-netinfoto detect network type.
OkHttp with HTTP/2 preserved:
val client = OkHttpClient.Builder()
.protocols(listOf(Protocol.HTTP_2, Protocol.HTTP_1_1))
.connectionPool(ConnectionPool(5, 5, TimeUnit.MINUTES))
.connectTimeout(10, TimeUnit.SECONDS)
.callTimeout(20, TimeUnit.SECONDS)
.build()
3. Compression
Always request and accept compressed responses. Brotli beats gzip by 15–25% on JSON; Zstd is competitive and widely deployed in 2026.
Accept-Encoding: br, zstd, gzip
- OkHttp: Brotli support via
BrotliInterceptor. - URLSession: gzip built-in; Brotli requires a custom decoder.
- Server: enable
brat the CDN edge for JSON APIs.
4. Trim Payloads
Shave bytes before you compress them:
- Avoid over-fetching. Use GraphQL or server-side field selection (
?fields=id,title,thumb). - Use short JSON keys (
{"t":"..."}vs{"title":"..."}) — gains compound after Brotli. - Use MessagePack, Protobuf, or CBOR for latency-critical APIs. Protobuf parses ~5× faster than JSON on mobile.
- Strip base64-encoded fields; fetch binaries as binaries.
- Move heavy fields behind
include=flags; fetch only on detail screens.
5. Keep Connections Warm
-
Use a shared
OkHttpClient/URLSessioninstance for the app's lifetime. Connection pools + DNS cache are instance-scoped. -
Preconnect to critical hosts at app start (after first frame):
Android OkHttp:
client.dispatcher.executorService.execute { Request.Builder().url("https://api.example.com/ping").head().build().let { req -> runCatching { client.newCall(req).execute().close() } } }iOS: warm by creating the session and doing a zero-cost HEAD /
nw_establishment_report.
6. Caching Headers
Make caching declarative at the edge; the client library honors standard headers automatically.
Cache-Control: public, max-age=60, stale-while-revalidate=600, stale-if-error=86400
ETag: "abc123"
Vary: Accept, Accept-Encoding
stale-while-revalidateis perfect for feeds — serve instantly, refresh in background.- See
request-batching-and-cachingskill for client-side patterns.
7. Image-Specific Tactics
- CDN responsive sizes:
/img/abc.jpg?w=720&q=80&fm=avif. - Prefer AVIF/WebP; see
bitmap-and-image-optimization. - Use
loading=lazyequivalents in RN (FastImagepriority="low"). - See
image-deliveryskill.
8. Avoid Common Footguns
- Do not disable HTTPS or pin weakly. Mobile carriers rewrite HTTP responses (injected ads, GZIP stripping) — HTTPS is also a perf feature.
- Do not bundle request and response interceptors that decompress twice.
- Do not serialize large objects on the UI thread.
Gson.toJson(list)on main is a classic jank cause. - Do not send timestamp as strings when you use them; sending epoch millis avoids parse cost.
- Do not send analytics events one-by-one over the wire; batch (see
background-work-optimization).
9. Measure
- Android: Profiler → Network view shows bytes, request/response timing. OkHttp
EventListenerlogs DNS, connect, TLS, response. - iOS: Instruments Network template;
URLSessiontaskMetrics(URLSessionTaskMetrics) — sum DNS, connect, TLS, wait, receive. - Flutter: DevTools → Network tab.
- RN: Flipper → Network plugin; Metro network inspector.
// URLSession taskMetrics
func urlSession(_ s: URLSession, task: URLSessionTask, didFinishCollecting m: URLSessionTaskMetrics) {
m.transactionMetrics.forEach { t in
let secure = t.negotiatedTLSProtocolVersion != nil
// log t.domainLookupStartDate, t.connectStartDate, t.secureConnectionStartDate, etc.
}
}
Checklist
- CDN serves HTTP/3 (Alt-Svc present) and clients use HTTP/2 as floor.
-
Accept-Encoding: br, zstd, gzipsent and honored. - Payloads audited; no overfetching; consider protobuf on hot paths.
- Shared HTTP client instance; connections preconnected at launch.
-
Cache-Control+ETag+stale-while-revalidateon all GET endpoints. - p95 bytes-per-screen and TTFB tracked in production dashboards.
- No JSON serialization on main/UI thread.
What ships with it
Read from the repository
Just SKILL.md. No reference files, no scripts.