···
if (meta.encoding === 'gzip' && meta.mimeType) {
54
-
// Serve gzipped content with proper headers
54
+
// Don't serve already-compressed media formats with Content-Encoding: gzip
55
+
// These formats (video, audio, images) are already compressed and the browser
56
+
// can't decode them if we add another layer of compression
57
+
const alreadyCompressedTypes = [
58
+
'video/', 'audio/', 'image/jpeg', 'image/jpg', 'image/png',
59
+
'image/gif', 'image/webp', 'application/pdf'
62
+
const isAlreadyCompressed = alreadyCompressedTypes.some(type =>
63
+
meta.mimeType.toLowerCase().startsWith(type)
66
+
if (isAlreadyCompressed) {
67
+
// Decompress the file before serving
68
+
console.log(`[DEBUG SERVE] ${requestPath}: decompressing already-compressed media type`);
69
+
const { gunzipSync } = await import('zlib');
70
+
const decompressed = gunzipSync(content);
71
+
console.log(`[DEBUG SERVE] ${requestPath}: decompressed from ${content.length} to ${decompressed.length} bytes`);
72
+
return new Response(decompressed, {
74
+
'Content-Type': meta.mimeType,
79
+
// Serve gzipped content with proper headers (for HTML, CSS, JS, etc.)
console.log(`[DEBUG SERVE] ${requestPath}: serving as gzipped with Content-Encoding header`);
return new Response(content, {
···
// Non-HTML files: serve gzipped content as-is with proper headers
const content = readFileSync(cachedFile);
182
+
// Don't serve already-compressed media formats with Content-Encoding: gzip
183
+
const alreadyCompressedTypes = [
184
+
'video/', 'audio/', 'image/jpeg', 'image/jpg', 'image/png',
185
+
'image/gif', 'image/webp', 'application/pdf'
188
+
const isAlreadyCompressed = alreadyCompressedTypes.some(type =>
189
+
mimeType.toLowerCase().startsWith(type)
192
+
if (isAlreadyCompressed) {
193
+
// Decompress the file before serving
194
+
const { gunzipSync } = await import('zlib');
195
+
const decompressed = gunzipSync(content);
196
+
return new Response(decompressed, {
198
+
'Content-Type': mimeType,
return new Response(content, {
'Content-Type': mimeType,