File tree Expand file tree Collapse file tree 1 file changed +8
-2
lines changed
Expand file tree Collapse file tree 1 file changed +8
-2
lines changed Original file line number Diff line number Diff line change @@ -64,13 +64,19 @@ where
6464}
6565
6666pub 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 {
You can’t perform that action at this time.
0 commit comments