Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CSS from LittleFS file #49

Open
chrisweather opened this issue Jun 12, 2023 · 1 comment
Open

CSS from LittleFS file #49

chrisweather opened this issue Jun 12, 2023 · 1 comment

Comments

@chrisweather
Copy link

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

@tfry-git
Copy link
Owner

tfry-git commented Jul 18, 2023

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])

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants