feat: implement template processor for dynamic HTML variable replacement and optimize static asset serving with caching
This commit is contained in:
1 parent
0f8d3d470d
commit
a3dd4b164e
4 files changed
+49
-51
No files matched your search
+12
-2
@@ -57,10 +57,20 @@ String readFile(const char* filename) {
|
||||
Serial.println(filename);
|
||||
return "";
|
||||
}
|
||||
String content = "";
|
||||
|
||||
// Effizient: Speicher vorab allokieren und in Blöcken lesen
|
||||
// Alte Implementierung war O(n²) wegen Byte-für-Byte String-Konkatenation
|
||||
size_t fileSize = file.size();
|
||||
String content;
|
||||
content.reserve(fileSize + 1); // Speicher vorab allokieren
|
||||
|
||||
// Lese in 512-Byte Blöcken statt Byte für Byte
|
||||
char buffer[512];
|
||||
while (file.available()) {
|
||||
content += (char)file.read();
|
||||
size_t bytesRead = file.readBytes(buffer, sizeof(buffer));
|
||||
content.concat(buffer, bytesRead);
|
||||
}
|
||||
|
||||
file.close();
|
||||
return content;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user