diff options
| author | Elias Haugsbakk <[email protected]> | 2026-07-27 20:14:21 +0200 |
|---|---|---|
| committer | Elias Haugsbakk <[email protected]> | 2026-07-27 20:14:21 +0200 |
| commit | 1f1e3e640126a0fffb1e112d705276738b7dc167 (patch) | |
| tree | 38e1ca2154fc7b7ac5716ee0101ee9ad204e9ab7 | |
| parent | 98d17162a927e42747ea8304981d66bcc2bdd327 (diff) | |
update to not cache static data
| -rw-r--r-- | clams-server/src/main/java/no/eliashaugsbakk/clams/server/config/AppRoutes.java | 19 |
1 files changed, 16 insertions, 3 deletions
diff --git a/clams-server/src/main/java/no/eliashaugsbakk/clams/server/config/AppRoutes.java b/clams-server/src/main/java/no/eliashaugsbakk/clams/server/config/AppRoutes.java index b296f4f..4676165 100644 --- a/clams-server/src/main/java/no/eliashaugsbakk/clams/server/config/AppRoutes.java +++ b/clams-server/src/main/java/no/eliashaugsbakk/clams/server/config/AppRoutes.java @@ -23,9 +23,10 @@ public class AppRoutes implements EndpointGroup { before(ctx -> { String path = ctx.path(); - // Skip non-GET requests and API endpoints + // Skip non-GET requests, API endpoints, static resources, and queried requests if (!ctx.method().name().equalsIgnoreCase("GET") || path.startsWith("/api") + || isStaticResource(path) || ctx.queryString() != null) { return; } @@ -51,11 +52,15 @@ public class AppRoutes implements EndpointGroup { return; } - // 2. Cache GET responses + // 2. Cache GET responses for HTML pages + String contentType = ctx.contentType(); if (method.equalsIgnoreCase("GET") && !path.startsWith("/api") // exclude API responses + && !isStaticResource(path) // exclude static assets && ctx.queryString() == null // exclude queried pages - && ctx.status().getCode() == 200) { // only cache successful responses + && ctx.status().getCode() == 200 + && contentType != null + && contentType.contains("text/html")) { // only cache HTML responses String renderedHtml = ctx.result(); if (renderedHtml != null && !renderedHtml.isBlank()) { @@ -110,4 +115,12 @@ public class AppRoutes implements EndpointGroup { delete("media/{uuid}", appContext.getMediaController()::handleDeleteMedia); }); } + + private static boolean isStaticResource(String path) { + if (path == null) { + return false; + } + return path.startsWith("/css/") + || path.startsWith("/images/"); + } } |
