You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
1.**File Collection** (`src/file.ts`): Scans source directory recursively using glob, skips pre-compressed files (.gz, .br) if originals exist, detects duplicate files via SHA256 hashing
82
82
2.**Content Analysis** (`src/index.ts`): Determines MIME types using `mime-types` library, calculates MD5 hashes for ETag generation, groups files by extension for statistics
83
83
3.**Compression** (`src/index.ts`): Applies gzip level 9 compression, uses compressed version only when size reduction >15% and original >1024 bytes
84
-
4.**Code Generation** (`src/cppCode.ts`, `src/cppCodeEspIdf.ts`): Uses Handlebars templates with custom helpers (switch/case), generates engine-specific C++ code with conditional compilation support
85
-
5.**Output**: Writes optimized header with embedded binary data arrays, route handlers, ETag strings, and C++ defines for validation
84
+
4.**Code Generation** (`src/cppCode.ts`, `src/cppCodeEspIdf.ts`): Uses Handlebars templates with custom helpers (switch/case), generates optimized engine-specific C++ code with:
85
+
- Inlined lambda handlers (ESPAsyncWebServer)
86
+
- Optimized header lookups for ETag validation (all engines)
87
+
- Proper const-correctness and modern C++ patterns
88
+
- Conditional compilation support for etag/gzip options
89
+
5.**Output**: Writes optimized header with embedded binary data arrays, route handlers with ETag validation, ETag MD5 strings, and C++ defines for build-time validation
-**Automatic Gzip Compression**: Compresses assets when size reduction >15% and >1024 bytes
97
-
-**ETag Support**: HTTP cache validation for reduced network traffic
101
+
-**ETag Support**: HTTP cache validation for reduced network traffic with 304 Not Modified responses across all engines (psychic, psychic2, async, espidf)
98
102
-**Cache Control**: Configurable browser caching with `--cachetime`
99
103
-**Multi-Engine Support**: Generate code for different ESP web server libraries
100
104
-**File Type Analysis**: Groups files by extension with count statistics
101
105
-**Memory Optimization**: Binary data stored as const arrays in program memory
106
+
-**Optimized C++ Code**: Generated code uses modern C++ best practices with minimal overhead
102
107
103
108
## Development Environment
104
109
@@ -131,6 +136,8 @@ The `package.script` executable generates 36 test header files (9 combinations o
131
136
-`index.html` or `index.htm` files are automatically set as the default route for "/"
132
137
- Pre-compressed files (.gz, .br, .brottli) in the source directory are skipped if the original file exists
133
138
- The build uses `--clean` and `--force` flags to ensure clean builds without incremental compilation
139
+
- ESP-IDF engine includes required headers (`string.h`, `stdlib.h`) for ETag validation support
140
+
- All engines now fully support HTTP 304 Not Modified responses for efficient caching
134
141
135
142
## Template System
136
143
@@ -141,6 +148,32 @@ The code generation uses Handlebars with custom helpers:
141
148
-**Engine-specific templates**: Each engine (psychic, psychic2, async, espidf) has its own template in `src/cppCode.ts` or `src/cppCodeEspIdf.ts`
142
149
-**Data transformation**: Binary content is converted to comma-separated byte arrays in the template data
143
150
151
+
## Generated C++ Code Quality
152
+
153
+
The generated C++ code follows modern best practices and is optimized for performance and maintainability:
154
+
155
+
### ETag Validation Implementation
156
+
157
+
All four engines support ETag validation with HTTP 304 Not Modified responses:
158
+
159
+
-**ESPAsyncWebServer (`async`)**: Uses `const AsyncWebHeader*` for proper const-correctness, single `getHeader()` call instead of `hasHeader()` + `getHeader()`, inlined lambda handlers
160
+
-**PsychicHttpServer (`psychic`, `psychic2`)**: Uses `request->header().equals()` for direct string comparison without temporary objects
161
+
-**ESP-IDF (`espidf`)**: Uses `httpd_req_get_hdr_value_len()` and `httpd_req_get_hdr_value_str()` for header validation with proper memory management (malloc/free)
162
+
163
+
### Code Optimizations
164
+
165
+
-**No intermediate variables**: Lambda handlers are inlined directly in route registration (ESPAsyncWebServer)
166
+
-**Optimized header lookups**: Single API call instead of redundant checks
@@ -242,6 +242,8 @@ Since microcontroller data traffic is moderately expensive, it is an individual
242
242
243
243
The use of ETag is **not enabled by default**, this can be achieved with the `--etag=true` switch.
244
244
245
+
All four engines (psychic, psychic2, async, espidf) fully support ETag validation with HTTP 304 Not Modified responses, reducing bandwidth usage when clients have valid cached content.
246
+
245
247
> This setting has three states: yes, no, and compiler mode is available. In compiler mode, you can disable/enable ETag by setting the `SVELTEESP32_ENABLE_ETAG` c++ compiler directive. For example, if using platformio, just type `-D SVELTEESP32_ENABLE_ETAG`.
0 commit comments