@@ -20,12 +20,6 @@ import { LRUCache } from './utils/lru-cache';
20
20
import { AngularBootstrap , renderAngular } from './utils/ng' ;
21
21
import { joinUrlParts , stripIndexHtmlFromURL , stripLeadingSlash } from './utils/url' ;
22
22
23
- /**
24
- * The default maximum age in seconds.
25
- * Represents the total number of seconds in a 365-day period.
26
- */
27
- const DEFAULT_MAX_AGE = 365 * 24 * 60 * 60 ;
28
-
29
23
/**
30
24
* Maximum number of critical CSS entries the cache can store.
31
25
* This value determines the capacity of the LRU (Least Recently Used) cache, which stores critical CSS for pages.
@@ -188,18 +182,19 @@ export class AngularServerApp {
188
182
return null ;
189
183
}
190
184
191
- // TODO(alanagius): handle etags
192
-
193
- const content = await this . assets . getServerAsset ( assetPath ) ;
194
-
195
- return new Response ( content , {
196
- headers : {
197
- 'Content-Type' : 'text/html;charset=UTF-8' ,
198
- // 30 days in seconds
199
- 'Cache-Control' : `max-age=${ DEFAULT_MAX_AGE } ` ,
200
- ...headers ,
201
- } ,
202
- } ) ;
185
+ const { text, hash, size } = this . assets . getServerAsset ( assetPath ) ;
186
+ const etag = `"${ hash } "` ;
187
+
188
+ return request . headers . get ( 'if-none-match' ) === etag
189
+ ? new Response ( undefined , { status : 304 , statusText : 'Not Modified' } )
190
+ : new Response ( await text ( ) , {
191
+ headers : {
192
+ 'Content-Length' : size . toString ( ) ,
193
+ 'ETag' : etag ,
194
+ 'Content-Type' : 'text/html;charset=UTF-8' ,
195
+ ...headers ,
196
+ } ,
197
+ } ) ;
203
198
}
204
199
205
200
/**
@@ -309,8 +304,10 @@ export class AngularServerApp {
309
304
} ,
310
305
) ;
311
306
} else if ( renderMode === RenderMode . Client ) {
312
- // Serve the client-side rendered version if the route is configured for CSR.
313
- return new Response ( await this . assets . getServerAsset ( 'index.csr.html' ) , responseInit ) ;
307
+ return new Response (
308
+ await this . assets . getServerAsset ( 'index.csr.html' ) . text ( ) ,
309
+ responseInit ,
310
+ ) ;
314
311
}
315
312
}
316
313
@@ -327,7 +324,7 @@ export class AngularServerApp {
327
324
} ) ;
328
325
}
329
326
330
- let html = await assets . getIndexServerHtml ( ) ;
327
+ let html = await assets . getIndexServerHtml ( ) . text ( ) ;
331
328
// Skip extra microtask if there are no pre hooks.
332
329
if ( hooks . has ( 'html:transform:pre' ) ) {
333
330
html = await hooks . run ( 'html:transform:pre' , { html, url } ) ;
@@ -348,7 +345,7 @@ export class AngularServerApp {
348
345
this . inlineCriticalCssProcessor ??= new InlineCriticalCssProcessor ( ( path : string ) => {
349
346
const fileName = path . split ( '/' ) . pop ( ) ?? path ;
350
347
351
- return this . assets . getServerAsset ( fileName ) ;
348
+ return this . assets . getServerAsset ( fileName ) . text ( ) ;
352
349
} ) ;
353
350
354
351
// TODO(alanagius): remove once Node.js version 18 is no longer supported.
0 commit comments