@@ -20,12 +20,6 @@ import { LRUCache } from './utils/lru-cache';
2020import { AngularBootstrap , renderAngular } from './utils/ng' ;
2121import { joinUrlParts , stripIndexHtmlFromURL , stripLeadingSlash } from './utils/url' ;
2222
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-
2923/**
3024 * Maximum number of critical CSS entries the cache can store.
3125 * 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 {
188182 return null ;
189183 }
190184
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+ } ) ;
203198 }
204199
205200 /**
@@ -309,8 +304,10 @@ export class AngularServerApp {
309304 } ,
310305 ) ;
311306 } 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+ ) ;
314311 }
315312 }
316313
@@ -327,7 +324,7 @@ export class AngularServerApp {
327324 } ) ;
328325 }
329326
330- let html = await assets . getIndexServerHtml ( ) ;
327+ let html = await assets . getIndexServerHtml ( ) . text ( ) ;
331328 // Skip extra microtask if there are no pre hooks.
332329 if ( hooks . has ( 'html:transform:pre' ) ) {
333330 html = await hooks . run ( 'html:transform:pre' , { html, url } ) ;
@@ -348,7 +345,7 @@ export class AngularServerApp {
348345 this . inlineCriticalCssProcessor ??= new InlineCriticalCssProcessor ( ( path : string ) => {
349346 const fileName = path . split ( '/' ) . pop ( ) ?? path ;
350347
351- return this . assets . getServerAsset ( fileName ) ;
348+ return this . assets . getServerAsset ( fileName ) . text ( ) ;
352349 } ) ;
353350
354351 // TODO(alanagius): remove once Node.js version 18 is no longer supported.
0 commit comments