diff --git a/lib/SvelteUi/include/AmsWebHeaders.h b/lib/SvelteUi/include/AmsWebHeaders.h index f7d9f60f..d254ebb0 100644 --- a/lib/SvelteUi/include/AmsWebHeaders.h +++ b/lib/SvelteUi/include/AmsWebHeaders.h @@ -1,10 +1,12 @@ static const char HEADER_CACHE_CONTROL[] PROGMEM = "Cache-Control"; +static const char HEADER_CONTENT_ENCODING[] PROGMEM = "Content-Encoding"; static const char HEADER_PRAGMA[] PROGMEM = "Pragma"; static const char HEADER_EXPIRES[] PROGMEM = "Expires"; static const char HEADER_AUTHENTICATE[] PROGMEM = "WWW-Authenticate"; static const char HEADER_LOCATION[] PROGMEM = "Location"; static const char CACHE_CONTROL_NO_CACHE[] PROGMEM = "no-cache, no-store, must-revalidate"; +static const char CONTENT_ENCODING_GZIP[] PROGMEM = "gzip"; static const char CACHE_1HR[] PROGMEM = "public, max-age=3600"; static const char CACHE_1MO[] PROGMEM = "public, max-age=2592000"; static const char PRAGMA_NO_CACHE[] PROGMEM = "no-cache"; diff --git a/lib/SvelteUi/scripts/generate_includes.py b/lib/SvelteUi/scripts/generate_includes.py index 0b75a3ce..f74c62bd 100644 --- a/lib/SvelteUi/scripts/generate_includes.py +++ b/lib/SvelteUi/scripts/generate_includes.py @@ -2,6 +2,7 @@ import os import re import shutil import subprocess +import gzip try: from css_html_js_minify import html_minify, js_minify, css_minify @@ -65,16 +66,24 @@ for webroot in ["lib/SvelteUi/app/dist", "lib/SvelteUi/json"]: content = js_minify(content) except: print("WARN: Unable to minify") - + + content_bytes = content.encode("utf-8") + if filename in ["index.js", "index.css"]: + content_bytes = gzip.compress(content_bytes, compresslevel=9) + content_len = len(content_bytes) + else: + content_len = len(content_bytes) + content_bytes += b"\0" + with open(dstfile, "w") as dst: dst.write("static const char ") dst.write(varname) - dst.write("[] PROGMEM = R\"==\"==(") - dst.write(content) - dst.write(")==\"==\";\n") + dst.write("[] PROGMEM = {") + dst.write(", ".join([str(c) for c in content_bytes])) + dst.write("};\n") dst.write("const int "); dst.write(varname) dst.write("_LEN PROGMEM = "); - dst.write(str(len(content))) + dst.write(str(content_len)) dst.write(";"); \ No newline at end of file diff --git a/lib/SvelteUi/src/AmsWebServer.cpp b/lib/SvelteUi/src/AmsWebServer.cpp index a3754653..d043ec2d 100644 --- a/lib/SvelteUi/src/AmsWebServer.cpp +++ b/lib/SvelteUi/src/AmsWebServer.cpp @@ -765,8 +765,8 @@ void AmsWebServer::indexCss() { return; server.sendHeader(HEADER_CACHE_CONTROL, CACHE_1MO); - server.setContentLength(INDEX_CSS_LEN); - server.send_P(200, MIME_CSS, INDEX_CSS); + server.sendHeader(HEADER_CONTENT_ENCODING, CONTENT_ENCODING_GZIP); + server.send_P(200, MIME_CSS, INDEX_CSS, INDEX_CSS_LEN); } void AmsWebServer::indexJs() { @@ -776,7 +776,8 @@ void AmsWebServer::indexJs() { return; server.sendHeader(HEADER_CACHE_CONTROL, CACHE_1MO); - server.send_P(200, MIME_JS, INDEX_JS); + server.sendHeader(HEADER_CONTENT_ENCODING, CONTENT_ENCODING_GZIP); + server.send_P(200, MIME_JS, INDEX_JS, INDEX_JS_LEN); } void AmsWebServer::configurationJson() {