Skip to content

web: serve static files with caching headers #2708

Description

@acinader

hledger-web sends no caching headers on /static/*

$ curl -sI http://127.0.0.1:5000/static/js/jquery.min.js
HTTP/1.1 200 OK
Connection: close
Date: ...
Server: Warp/3.4.13.1
Content-Type: text/javascript
Vary: Accept-Encoding

Every page view refetches every asset: 9 files, ~112KB, per navigation.

Impact

Nothing on loopback. Serving the static files from memory, so they cost nothing at all,
leaves navigation time unchanged (p50 67ms either way) — the requests overlap with parsing
and executing the page, and the bytes are free locally.

Over a network it is the dominant cost. At 12 Mbps / 40ms RTT:

p50 p90
as shipped 284 ms 316 ms
static files cached 117 ms 134 ms

Cache invalidation

Long-lived caching needs the url to change when the file does, or an upgraded hledger keeps
serving the old javascript and css from cache. Content-hashed urls do that, but should not become
version numbers maintained by hand in templates.

The static files are already embedded at compile time, so the hash can come from the build.
Yesod's static subsite has support for this; worth checking what comes for free before
designing anything.

If hashed urls turn out to be awkward, ETag/Last-Modified alone still avoids re-sending
the bytes and cannot go stale.

Where

Hledger/Web/Settings/StaticFiles.hs builds the subsite with embed staticDir and generates
routes with publicFiles, giving unhashed paths like /static/js/jquery.min.js.

Independent of #2702 and #2705.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-WISHSome kind of improvement request or proposal.webThe hledger-web tool.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions