EmbAJAX icon indicating copy to clipboard operation
EmbAJAX copied to clipboard

CSS from LittleFS file

Open chrisweather opened this issue 2 years ago • 1 comments

Hi Thomas, thanks for your great work. I'm looking for a way to store a css file on the ESP in LittleFS instead of referencing a css file on an external link. Any hints if this is currently possible? Thanks Chris

chrisweather avatar Jun 12 '23 16:06 chrisweather

Hi!

Sorry for the long delay. This is definitely possible, but somewhat out of scope for EmbAJAX itself. Note that EmbAJAX itself utilizes the whatever webserver implementation is available for your board. For most (ESPAsyncWebServer being slightly different), the procedure will be something like:

// at global scope
void serveCss() {
    File file = fileSystem->open("my.css", "r");
    server.streamFile(file, "text/css");
    file.close();
}

// in setup():
server.on("/my.css", serveCss);

Now, the only thing to do in EmbAJAX is to add a corresponding link to your file in the page header:

MAKE_EmbAJAXPage(page, "EmbAJAXTest", "<link rel=\"stylesheet\" href=\"/my.css\">", [elements])

tfry-git avatar Jul 18 '23 15:07 tfry-git