Skip to content

Add support for HTTP ETags in llama-server#23701

Merged
ngxson merged 3 commits into
ggml-org:masterfrom
mtavenrath:cache-web-ui
May 28, 2026
Merged

Add support for HTTP ETags in llama-server#23701
ngxson merged 3 commits into
ggml-org:masterfrom
mtavenrath:cache-web-ui

Conversation

@mtavenrath

Copy link
Copy Markdown
Contributor

Overview

The user interface of llama-server is served as embedded static files. For those files the httplib does not generate ETags used for browser caching. This change computes a hash for each statically embedded file to allow caching.

The javascript bundles has a size of around 5MB and it can take a considerable amount of time in low bandwidth environments to download this file each time one opens the llama-server webinterface. Using caching those files have to be downloaded only once.

Requirements

  • I have read and agree with the contributing guidelines

  • AI usage disclosure: yes: I have used an AI coding to understand llama-server and made it generate the required changes. I reworked the changes with AI to be minimal intrusive to avoid AI slop / bloat.

@mtavenrath mtavenrath requested review from a team as code owners May 26, 2026 05:27
Comment thread tools/server/server-http.cpp Outdated
if (const std::string & inm = req.get_header_value("If-None-Match");
!inm.empty() && inm == a->etag) {
res.status = 304;
res.set_header("ETag", a->etag);

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

An alternative to a hash based etag could be a compile date + time based etag. The advantage here would be that the etag doesn't have to be computed with xxhash removing this dependency with the downside of having to redownloading the ui files after each rebuild.

@ngxson ngxson left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO the better implementation is to simply calculate the hash at compile time, not at runtime

@mtavenrath

Copy link
Copy Markdown
Contributor Author

The hash is compiled during the embedding phase during compile time.

Comment thread tools/ui/CMakeLists.txt Outdated
Comment thread tools/server/server-http.cpp Outdated
@ngxson ngxson requested a review from ServeurpersoCom May 26, 2026 11:40
etag has to be set always

Co-authored-by: Xuan-Son Nguyen <thichthat@gmail.com>
@mtavenrath

Copy link
Copy Markdown
Contributor Author

When trying to reproduce this locally I worked around multiple issues to make the E2E tests run successfully. My AI told me that Playwright 1.56.1 expects a headless shell while the chromium build installed through npx playwright install chromium was a full chrome binary. When installing the headless_shell the test succeeds with chromium. It also succeeds with Firefox on my system.

@ngxson

ngxson commented May 28, 2026

Copy link
Copy Markdown
Collaborator

the E2E test is not run via llama-server, so it's safe to ignore the error

@ngxson ngxson merged commit d205df6 into ggml-org:master May 28, 2026
33 of 34 checks passed
adrianhoehne pushed a commit to adrianhoehne/llama.cpp that referenced this pull request May 28, 2026
* allow caching of ui elements in llama-server

* use fnv_hash

* Update tools/server/server-http.cpp

etag has to be set always

Co-authored-by: Xuan-Son Nguyen <thichthat@gmail.com>

---------

Co-authored-by: Xuan-Son Nguyen <thichthat@gmail.com>
fewtarius pushed a commit to fewtarius/llama.cpp that referenced this pull request May 30, 2026
* allow caching of ui elements in llama-server

* use fnv_hash

* Update tools/server/server-http.cpp

etag has to be set always

Co-authored-by: Xuan-Son Nguyen <thichthat@gmail.com>

---------

Co-authored-by: Xuan-Son Nguyen <thichthat@gmail.com>
turbo-tan pushed a commit to turbo-tan/llama.cpp-tq3 that referenced this pull request Jun 2, 2026
* allow caching of ui elements in llama-server

* use fnv_hash

* Update tools/server/server-http.cpp

etag has to be set always

Co-authored-by: Xuan-Son Nguyen <thichthat@gmail.com>

---------

Co-authored-by: Xuan-Son Nguyen <thichthat@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants