Skip to content

Commit 29e9c73

Browse files
authored
Make omggif.js available as an independent resource, improved sequential loading in cpal (#5362)
* take omggif out of pixelforge.htm, improved sequential loading in cpal * add js_omggif.h to build output list
1 parent 6240ee6 commit 29e9c73

4 files changed

Lines changed: 141 additions & 123 deletions

File tree

tools/cdata.js

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ const packageJson = require("../package.json");
2626
// Export functions for testing
2727
module.exports = { isFileNewerThan, isAnyFileInFolderNewerThan };
2828

29-
const output = ["wled00/html_ui.h", "wled00/html_pixart.h", "wled00/html_cpal.h", "wled00/html_edit.h", "wled00/html_pxmagic.h", "wled00/html_pixelforge.h", "wled00/html_settings.h", "wled00/html_other.h", "wled00/js_iro.h"]
29+
const output = ["wled00/html_ui.h", "wled00/html_pixart.h", "wled00/html_cpal.h", "wled00/html_edit.h", "wled00/html_pxmagic.h", "wled00/html_pixelforge.h", "wled00/html_settings.h", "wled00/html_other.h", "wled00/js_iro.h", "wled00/js_omggif.h"]
3030

3131
// \x1b[34m is blue, \x1b[36m is cyan, \x1b[0m is reset
3232
const wledBanner = `
@@ -271,6 +271,20 @@ writeChunks(
271271
"wled00/js_iro.h"
272272
);
273273

274+
writeChunks(
275+
"wled00/data/pixelforge",
276+
[
277+
{
278+
file: "omggif.js",
279+
name: "JS_omggif",
280+
method: "gzip",
281+
filter: "js-minify",
282+
mangle: (s) => s.replace(/^\/\*![\s\S]*?\*\//, '') // remove license comment at the top
283+
}
284+
],
285+
"wled00/js_omggif.h"
286+
);
287+
274288
writeChunks(
275289
"wled00/data",
276290
[

wled00/data/cpal/cpal.htm

Lines changed: 8 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -73,28 +73,15 @@
7373
let maxCol; // max colors to send out in one chunk, ESP8266 is limited to ~50 (500 bytes), ESP32 can do ~128 (1340 bytes)
7474

7575
// load external resources in sequence to avoid 503 errors if heap is low, repeats indefinitely until loaded
76-
// load CSS
77-
const l1 = document.createElement('link');
78-
l1.rel = 'stylesheet';
79-
l1.href = 'style.css';
80-
l1.onload = () => {
81-
// load iro.js
82-
const l2 = document.createElement('script');
83-
l2.src = 'iro.js';
84-
l2.onload = () => {
85-
// load common.js
86-
const l3 = document.createElement('script');
87-
l3.src = 'common.js';
88-
// initialize when all documents are loaded
89-
l3.onload = () => document.readyState === 'complete' ? init() : window.addEventListener('load', init);
90-
l3.onerror = () => setTimeout(() => document.head.appendChild(l3), 100);
91-
document.head.appendChild(l3);
76+
(function loadFiles() {
77+
const s = document.createElement('script');
78+
s.src = 'common.js';
79+
s.onerror = () => setTimeout(loadFiles, 100);
80+
s.onload = () => {
81+
loadResources(['style.css', 'iro.js'], init);
9282
};
93-
l2.onerror = () => setTimeout(() => document.head.appendChild(l2), 100);
94-
document.head.appendChild(l2);
95-
};
96-
l1.onerror = () => setTimeout(() => document.head.appendChild(l1), 100);
97-
document.head.appendChild(l1);
83+
document.head.appendChild(s);
84+
})();
9885

9986
// main init function, called when all resources are loaded
10087
function init() {

0 commit comments

Comments
 (0)