From 1f1e3e640126a0fffb1e112d705276738b7dc167 Mon Sep 17 00:00:00 2001 From: Elias Haugsbakk Date: Mon, 27 Jul 2026 20:14:21 +0200 Subject: update to not cache static data --- .../eliashaugsbakk/clams/server/config/AppRoutes.java | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) (limited to 'clams-server') 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/"); + } } -- cgit v1.2.3