Reduce media bandwidth: compress uploads, add long-lived cache headers, gzip API
- Resize/re-encode every uploaded image server-side (posts, avatars, stories, shop products/logo, chat messages) via a shared sharp-based optimizer — caps dimensions to what's actually displayed and re-compresses in place, cutting a typical raw camera photo by ~90% with no visible quality loss - Cap uploaded video resolution/bitrate (re-encode only when above 1280px/ ~2.5Mbps) alongside the existing faststart step; apply faststart+cap to story and chat videos too (previously stored completely raw) - Add long-lived Cache-Control to all /storage static routes so clients stop re-downloading unchanged media on every request - Add gzip/brotli compression for JSON API responses (feed/explore/chat) Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
const fs = require('fs-extra')
|
||||
const path = require('path')
|
||||
const axios = require('axios')
|
||||
const { optimizeImageFile } = require('./imageOptimize')
|
||||
|
||||
const EXT_BY_CONTENT_TYPE = {
|
||||
'image/png': '.png',
|
||||
@@ -32,6 +33,7 @@ async function downloadImageToProfiles(url, baseName) {
|
||||
const filePath = path.join(uploadDir, uniqueFileName)
|
||||
|
||||
await fs.writeFile(filePath, Buffer.from(response.data))
|
||||
await optimizeImageFile(filePath, { maxDimension: 800 })
|
||||
|
||||
return `/profiles/${uniqueFileName}`
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user