diff --git a/embed_files.sh b/embed_files.sh
new file mode 100644
index 000000000..0eed06092
--- /dev/null
+++ b/embed_files.sh
@@ -0,0 +1,82 @@
+#!/bin/bash
+
+#
+# This script walks through the assets folder and minifys all JS, HTML, CSS and SVG files. It also generates
+# the corresponding constants that are added to the data.h file on esp8266_deauther folder.
+#
+# @Author Erick B. Tedeschi < erickbt86 [at] gmail [dot] com >
+# @Author Wandmalfarbe https://github.com/Wandmalfarbe
+#
+# See: https://github.com/letscontrolit/ESPEasy/issues/1671#issuecomment-415144898
+
+outputfile="$(pwd)/data_h_temp"
+
+rm $outputfile
+
+function minify_html_css {
+ file=$1
+ curl -X POST -s --data-urlencode "input@$file" http://html-minifier.com/raw > /tmp/converter.temp
+}
+
+function minify_js {
+ file=$1
+ curl -X POST -s --data-urlencode "input@$file" https://javascript-minifier.com/raw > /tmp/converter.temp
+}
+
+function minify_svg {
+ file=$1
+ svgo -i /Users/User/Desktop/icons/tools.svg -o - > /tmp/converter.temp
+}
+
+function ascii2hexCstyle {
+ file_name=$(constFileName $1)
+ result=$(cat /tmp/converter.temp | hexdump -ve '1/1 "0x%.2x,"')
+ result=$(echo $result | sed 's/,$//')
+ echo "const char DATA_${file_name}[] PROGMEM = {$result};"
+}
+
+function constFileName {
+ extension=$(echo $1 | egrep -io "(json|svg|css|js|html)$" | tr "[:lower:]" "[:upper:]")
+ file=$(echo $1 | sed 's/\.json//' | sed 's/\.svg//' | sed 's/\.css//' | sed 's/\.html//' | sed 's/\.js//' | sed 's/\.\///' | tr '/' '_' | tr '.' '_' | tr '-' '_' | tr "[:lower:]" "[:upper:]")
+ underscore="_"
+ echo $file$underscore$extension
+}
+
+
+cd static
+file_list=$(find . -type f)
+
+for file in $file_list; do
+ echo "Processing: $file"
+ file_name=$(constFileName $file)
+ echo " Array Name: $file_name"
+
+ if [[ "$file" == *.min.js ]]; then
+ echo " JS already minified"
+ cat $file > /tmp/converter.temp
+ ascii2hexCstyle $file >> $outputfile
+ elif [[ "$file" == *.js ]]; then
+ echo " JS minify"
+ minify_js $file
+ ascii2hexCstyle $file >> $outputfile
+ elif [[ "$file" == *.min.css ]]; then
+ echo " CSS already minified"
+ cat $file > /tmp/converter.temp
+ ascii2hexCstyle $file >> $outputfile
+ elif [[ "$file" == *.html ]] || [[ "$file" == *.css ]]; then
+ echo " HTML and CSS minify"
+ minify_html_css $file
+ ascii2hexCstyle $file >> $outputfile
+ elif [[ "$file" == *.svg ]]; then
+ echo " SVG minify"
+ minify_svg $file
+ ascii2hexCstyle $file >> $outputfile
+ else
+ echo " without minifier"
+ cat $file > /tmp/converter.temp
+ ascii2hexCstyle $file >> $outputfile
+ fi
+ echo ""
+ sleep 1
+done
+
diff --git a/src/WebServer.ino b/src/WebServer.ino
index c16c74c5d..691f0bc61 100644
--- a/src/WebServer.ino
+++ b/src/WebServer.ino
@@ -288,8 +288,10 @@ void sendHeadandTail(const String& tmplName, boolean Tail = false, boolean reboo
}
}
if (shouldReboot) {
- //we only add this here as a seperate chucnk to prevent using too much memory at once
- TXBuffer += jsReboot;
+ //we only add this here as a seperate chunk to prevent using too much memory at once
+ html_add_script(false);
+ TXBuffer += DATA_REBOOT_JS;
+ html_add_script_end();
}
}
@@ -732,7 +734,7 @@ void getWebPageTemplateVar(const String& varName )
{
TXBuffer += F("");
}
}
@@ -783,7 +785,7 @@ void writeDefaultCSS(void)
log += F(" bytes)");
addLog(LOG_LEVEL_INFO, log);
}
- defaultCSS= PGMT(pgDefaultCSS);
+ defaultCSS= PGMT(DATA_ESPEASY_DEFAULT_MIN_CSS);
f.write((const unsigned char*)defaultCSS.c_str(), defaultCSS.length()); //note: content must be in RAM - a write of F("XXX") does not work
f.close();
}
@@ -2030,7 +2032,9 @@ void handle_devices() {
// show all tasks as table
if (taskIndexNotSet)
{
- TXBuffer += jsUpdateSensorValuesDevicePage;
+ html_add_script(true);
+ TXBuffer += DATA_UPDATE_SENSOR_VALUES_DEVICE_PAGE_JS;
+ html_add_script_end();
html_table_class_multirow();
html_TR();
html_table_header("", 70);
@@ -3180,6 +3184,19 @@ void html_add_autosubmit_form() {
"\n//-->");
}
+void html_add_script(bool defer) {
+ TXBuffer += F("");
+}
+
+
//********************************************************************************
// Add a task select dropdown list
//********************************************************************************
@@ -3264,7 +3281,9 @@ void handle_log() {
addCheckBox(F("autoscroll"), true);
TXBuffer += F("