Skip to content

Commit e4f5307

Browse files
committed
fix: don't cache json respones
1 parent 0db4879 commit e4f5307

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

crates/rostra-web-ui/src/routes.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,13 +64,19 @@ where
6464
}
6565

6666
pub async fn cache_control(request: Request, next: Next) -> Response {
67+
// Check if this is a static asset request (always cacheable)
68+
let is_static_asset = request.uri().path().starts_with("/assets/");
69+
6770
let mut response = next.run(request).await;
6871

6972
if let Some(content_type) = response.headers().get(CONTENT_TYPE) {
70-
const NON_CACHEABLE_CONTENT_TYPES: &[&str] = &["text/html"];
73+
const NON_CACHEABLE_CONTENT_TYPES: &[&str] = &["text/html", "application/json"];
7174
const SHORT_CACHE_CONTENT_TYPES: &[&str] = &["text/css"];
7275

73-
let cache_duration_secs = if SHORT_CACHE_CONTENT_TYPES
76+
let cache_duration_secs = if is_static_asset {
77+
// Static assets are always cacheable
78+
Some(60 * 60)
79+
} else if SHORT_CACHE_CONTENT_TYPES
7480
.iter()
7581
.any(|&ct| content_type.as_bytes().starts_with(ct.as_bytes()))
7682
{

0 commit comments

Comments
 (0)