-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathconfig.js
More file actions
177 lines (165 loc) · 4.61 KB
/
Copy pathconfig.js
File metadata and controls
177 lines (165 loc) · 4.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
/**
* Configuration for 2G Website Compressor
* Controls compression strategies, optimization toggles, and performance tuning
*/
module.exports = {
// Proxy server configuration
proxy: {
port: 8888,
host: '0.0.0.0',
// SSL/TLS configuration for HTTPS MITM
sslCaDir: './certs',
},
// Logging configuration
logging: {
level: process.env.LOG_LEVEL || 'info', // debug, info, warn, error
format: 'json', // json or pretty
},
// Compression strategy configuration
compression: {
// Brotli compression settings (text: HTML, CSS, JS)
brotli: {
enabled: true,
quality: 9, // 1-11; higher = better compression but slower. 9 = good balance
lgwin: 22, // Brotli window size (20-24); higher = better for large files
},
// Gzip fallback for clients that don't support Brotli
gzip: {
enabled: true,
level: 9, // 0-9; higher = better compression
},
},
// HTML optimization
html: {
enabled: true,
minify: true,
// Strip these scripts (analytics, ads, tracking)
stripScripts: [
'google-analytics',
'googletagmanager',
'analytics',
'facebook',
'twitter',
'instagram',
'ads',
'doubleclick',
'adsense',
],
// Remove these meta/link tags
removeMetaTags: [
'description', // Keep or remove? Keep for SEO
],
// Lazy-load images by default
lazyLoadImages: true,
// Remove non-essential attributes
minifyAttributes: true,
// Remove comments and whitespace
removeComments: true,
},
// Image optimization
image: {
enabled: true,
// Convert to WebP (better compression)
convertToWebP: true,
// WebP quality setting (1-100; 50-60 for aggressive 2G optimization)
webpQuality: 55,
// Maximum image width (fit to phone screens: e.g., 480px for older phones)
maxWidth: 480,
// Maximum image height (prevent huge vertical images)
maxHeight: 800,
// Downscale larger images aggressively
downscaleThreshold: 600, // If width > 600, always downscale
// JPEG quality fallback (for devices that don't support WebP)
jpegQuality: 60,
// Enable progressive JPEG
progressive: true,
},
// CSS optimization
css: {
enabled: true,
minify: true,
// Strip unused CSS prefixes (e.g., -webkit-, -moz-)
stripVendorPrefixes: false, // Keep false for compatibility
},
// JavaScript optimization
javascript: {
enabled: true,
minify: true,
// Remove console.* statements
removeConsole: true,
// Remove debugger statements
removeDebugger: true,
// Compress variable names
compress: true,
},
// Caching strategy
cache: {
enabled: true,
// Use server's Cache-Control headers
respectServerHeaders: true,
// Default TTL for cached responses (in seconds)
defaultTTL: 15 * 60, // 15 minutes
// Maximum cache size (in MB)
maxSize: 100,
// Cache storage location
storageDir: './cache',
},
// Request/Response filtering
filtering: {
// Domain whitelist (if empty, all domains allowed)
domainWhitelist: [],
// Domain blacklist (skip optimization for these)
domainBlacklist: [
'video.example.com', // Skip video-heavy sites
'stream.example.com',
],
// Content-Type whitelist for optimization
contentTypesOptimize: [
'text/html',
'text/css',
'text/javascript',
'application/javascript',
'application/x-javascript',
'image/jpeg',
'image/png',
'image/gif',
'image/webp',
],
// Skip optimization for these content types
contentTypesSkip: [
'video/',
'audio/',
'application/octet-stream',
'application/zip',
'application/pdf',
],
},
// Performance metrics & monitoring
metrics: {
enabled: true,
// Log compression ratio for each request
logCompressionRatio: true,
// Collect stats by domain
collectByDomain: true,
// Report metrics interval (seconds)
reportInterval: 60,
},
// Global request/response size limits
limits: {
// Maximum request size to cache (MB)
maxRequestSize: 50,
// Maximum response size to cache (MB)
maxResponseSize: 50,
// Skip optimization if original size is below (KB) — efficiency threshold
minSizeToOptimize: 0.1, // Compress everything (100 bytes+) - critical for 2G networks!
},
// Debug & testing
debug: {
enabled: process.env.DEBUG === 'true',
// Log all requests/responses
logAllRequests: false,
// Save original vs. compressed to disk for analysis
saveComparisons: false,
comparisonDir: './debug/comparisons',
},
};