@@ -220,7 +220,6 @@ export const setCacheControlHeaders = (
220220 . log ( 'NetlifyHeadersHandler.trailingSlashRedirect' )
221221 }
222222
223- const cacheControl = headers . get ( 'cache-control' )
224223 if ( status === 404 ) {
225224 if ( request . url . endsWith ( '.php' ) ) {
226225 // temporary CDN Cache Control handling for bot probes on PHP files
@@ -241,6 +240,8 @@ export const setCacheControlHeaders = (
241240 }
242241 }
243242
243+ const cacheControl = headers . get ( 'cache-control' )
244+
244245 if (
245246 cacheControl !== null &&
246247 [ 'GET' , 'HEAD' ] . includes ( request . method ) &&
@@ -273,6 +274,7 @@ export const setCacheControlHeaders = (
273274 [ 'GET' , 'HEAD' ] . includes ( request . method ) &&
274275 ! headers . has ( 'cdn-cache-control' ) &&
275276 ! headers . has ( 'netlify-cdn-cache-control' ) &&
277+ ! ( new URL ( request . url ) ) . pathname . startsWith ( '/api/' ) &&
276278 requestContext . usedFsReadForNonFallback
277279 ) {
278280 // handle CDN Cache Control on static files
@@ -281,13 +283,24 @@ export const setCacheControlHeaders = (
281283 }
282284}
283285
284- export const setCacheTagsHeaders = ( headers : Headers , requestContext : RequestContext ) => {
285- if (
286- requestContext . responseCacheTags &&
287- ( headers . has ( 'cache-control' ) || headers . has ( 'netlify-cdn-cache-control' ) )
288- ) {
286+ export const setCacheTagsHeaders = (
287+ headers : Headers ,
288+ request : Request ,
289+ requestContext : RequestContext ,
290+ ) => {
291+ if ( ! headers . has ( 'cache-control' ) && ! headers . has ( 'netlify-cdn-cache-control' ) ) {
292+ return
293+ }
294+
295+ if ( requestContext . responseCacheTags ) {
289296 headers . set ( 'netlify-cache-tag' , requestContext . responseCacheTags . join ( ',' ) )
297+ return
290298 }
299+
300+ const key = new URL ( request . url ) . pathname
301+ const cacheTag = `_N_T_${ key === '/index' ? '/' : encodeURI ( key ) } `
302+ console . log ( 'setCacheTagsHeaders' , 'netlify-cache-tag' , key )
303+ headers . set ( 'netlify-cache-tag' , cacheTag )
291304}
292305
293306/**
0 commit comments