@@ -61,26 +61,30 @@ export function staticFiles<T>(): MiddlewareFn<T> {
61
61
vary : "If-None-Match" ,
62
62
} ) ;
63
63
64
- if ( cacheKey === null || ctx . config . mode === "development" ) {
64
+ const ifNoneMatch = req . headers . get ( "If-None-Match" ) ;
65
+ if (
66
+ ifNoneMatch !== null &&
67
+ ( ifNoneMatch === etag || ifNoneMatch === `W/"${ etag } "` )
68
+ ) {
69
+ file . close ( ) ;
70
+ return new Response ( null , { status : 304 , headers } ) ;
71
+ } else if ( etag !== null ) {
72
+ headers . set ( "Etag" , `W/"${ etag } "` ) ;
73
+ }
74
+
75
+ if (
76
+ ctx . config . mode !== "development" &&
77
+ ( BUILD_ID === cacheKey ||
78
+ url . pathname . startsWith (
79
+ `${ ctx . config . basePath } /_fresh/js/${ BUILD_ID } /` ,
80
+ ) )
81
+ ) {
82
+ headers . append ( "Cache-Control" , "public, max-age=31536000, immutable" ) ;
83
+ } else {
65
84
headers . append (
66
85
"Cache-Control" ,
67
86
"no-cache, no-store, max-age=0, must-revalidate" ,
68
87
) ;
69
- } else {
70
- const ifNoneMatch = req . headers . get ( "If-None-Match" ) ;
71
- if (
72
- ifNoneMatch !== null &&
73
- ( ifNoneMatch === etag || ifNoneMatch === `W/"${ etag } "` )
74
- ) {
75
- file . close ( ) ;
76
- return new Response ( null , { status : 304 , headers } ) ;
77
- } else if ( etag !== null ) {
78
- headers . set ( "Etag" , `W/"${ etag } "` ) ;
79
- }
80
- }
81
-
82
- if ( BUILD_ID === cacheKey ) {
83
- headers . append ( "Cache-Control" , "public, max-age=31536000, immutable" ) ;
84
88
}
85
89
86
90
headers . set ( "Content-Length" , String ( file . size ) ) ;
0 commit comments