Files
cobble/src/utils/pick-content-encoding.ts
T
tbenandClaude Opus 5.5 c1a94fc9a5 Make pages load fast on mobile
- Compress responses: page scripts and styles once (brotli or gzip, in
  memory) and cached immutable; pages and API JSON gzipped as they stream
- Service worker serves content-named assets cache-first
- Load the models modal's data when it opens (cached in localStorage)
  instead of shipping the model catalog in every conversation page
- Lazy-load the Tiptap composer and memoize thread messages
- Import lucide icons directly; twui 0.1.4 drops by-name icons from Button
- bun run start builds the pages minified before serving

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-10-20 13:41:45 +01:00

33 lines
1020 B
TypeScript

export type ContentEncoding = "br" | "gzip";
type Params = {
accept_encoding?: string | null;
/**
* The encodings the caller can produce, preferred first.
*/
offer?: ContentEncoding[];
};
/**
* The encoding to compress a response with for this `Accept-Encoding`:
* the first of `offer` (brotli, then gzip) the client takes, else none. A
* coding listed with `q=0` is refused, and `*` takes anything.
*/
export default function pickContentEncoding({
accept_encoding,
offer = ["br", "gzip"],
}: Params): ContentEncoding | null {
if (!accept_encoding) return null;
const accepted = new Set(
accept_encoding
.toLowerCase()
.split(",")
.map((part) => part.trim().split(";").map((piece) => piece.trim()))
.filter(([, ...params]) => !params.some((param) => /^q=0(\.0*)?$/.test(param)))
.map(([coding]) => coding),
);
return offer.find((encoding) => accepted.has(encoding) || accepted.has("*")) ?? null;
}