@@ -31,6 +31,8 @@ interface ManifestLookupOptions {
31
31
branchOrRef : string ;
32
32
}
33
33
34
+ const FingerprintedExtensions = new Set ( [ '.css' , '.js' , '.svg' ] ) ;
35
+
34
36
export const getManifest = async ( siteId : string , branchOrRef : string ) => {
35
37
const keys = [
36
38
datastore . key ( [ 'Fileset2Manifest' , `${ siteId } :branch:${ branchOrRef } ` ] ) ,
@@ -301,6 +303,11 @@ export function createApp(siteId: string) {
301
303
urlPath += 'index.html' ;
302
304
}
303
305
306
+ // Used for cache-control settings.
307
+ const ext = fsPath . extname ( req . path . split ( '?' ) [ 0 ] ) ;
308
+ const isFingerprinted =
309
+ FingerprintedExtensions . has ( ext ) && req . url . includes ( 'fingerprint=' ) ;
310
+
304
311
// Handle static content.
305
312
const manifestPaths = manifest . paths ;
306
313
let blobKey =
@@ -382,7 +389,9 @@ export function createApp(siteId: string) {
382
389
delete proxyRes . headers [ 'x-goog-stored-content-length' ] ;
383
390
delete proxyRes . headers [ 'x-guploader-response-body-transformations' ] ;
384
391
delete proxyRes . headers [ 'x-guploader-uploadid' ] ;
385
- if ( isLive && ! is404Page ) {
392
+ if ( isFingerprinted ) {
393
+ proxyRes . headers [ 'cache-control' ] = 'public, max-age=31536000' ;
394
+ } else if ( isLive && ! is404Page ) {
386
395
// This cannot be "private, max-age=0" as this kills perf.
387
396
// This also can't be a very small value, as it kills perf. 0036 seems to work correctly.
388
397
// The padded "0036" keeps the Content-Length identical with `3600`.
0 commit comments