1
0
Fork 0
mirror of https://github.com/miniflux/v2.git synced 2025-08-11 17:51:01 +00:00

refactor(static): use a simple struct instead of two slices to store assets data and checksums

- Use a simple struct instead of two slices to store the data and the checksums
  of resources
- Remove a superfluous call to Sprintf
- Factorise presence check and data retrieval in some maps
- Size the maps when possible
This commit is contained in:
Julien Voisin 2025-08-06 04:35:27 +02:00 committed by GitHub
parent b1cbaae71c
commit 798bc4cd2d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 33 additions and 29 deletions

View file

@ -21,14 +21,14 @@ const licenseSuffix = "\n//@license-end"
func (h *handler) showJavascript(w http.ResponseWriter, r *http.Request) {
filename := request.RouteStringParam(r, "name")
etag, found := static.JavascriptBundleChecksums[filename]
js, found := static.JavascriptBundles[filename]
if !found {
html.NotFound(w, r)
return
}
response.New(w, r).WithCaching(etag, 48*time.Hour, func(b *response.Builder) {
contents := static.JavascriptBundles[filename]
response.New(w, r).WithCaching(js.Checksum, 48*time.Hour, func(b *response.Builder) {
contents := js.Data
if filename == "service-worker" {
variables := fmt.Sprintf(`const OFFLINE_URL=%q;`, route.Path(h.router, "offline"))