@@ -16,7 +16,7 @@ import {
1616 OIDCNotFoundPage ,
1717} from './pages-source' ;
1818import React from 'react' ;
19- import { gzipSync } from 'zlib' ;
19+ import { gzipSync , brotliCompressSync , constants as zlibConstants } from 'zlib' ;
2020import { writeFileSync } from 'fs' ;
2121import path from 'path' ;
2222import type { PageTemplates , ITemplate } from './types' ;
@@ -84,26 +84,23 @@ export function generateTemplates<TPage extends string = HttpServerPage>(
8484 return templates as PageTemplates < TPage > ;
8585}
8686
87- export function generateCompressedTemplates <
88- TPage extends string = HttpServerPage
89- > (
90- pages : Record <
91- TPage ,
92- {
93- Component : Component ;
94- parameters : string [ ] ;
95- }
96- >
97- ) : void {
98- const templates = generateTemplates ( pages ) ;
99- const buffer = gzipSync ( JSON . stringify ( templates ) ) ;
87+ function generateGzip ( data : string ) : void {
88+ const buffer = gzipSync ( data ) ;
10089 writeFileSync ( path . join ( __dirname , 'templates.gz' ) , buffer , 'binary' ) ;
90+ }
10191
92+ function generateJS ( data : string ) : void {
93+ const buffer = brotliCompressSync ( data , {
94+ params : {
95+ [ zlibConstants . BROTLI_PARAM_MODE ] : zlibConstants . BROTLI_MODE_TEXT ,
96+ [ zlibConstants . BROTLI_PARAM_QUALITY ] : zlibConstants . BROTLI_MAX_QUALITY ,
97+ } ,
98+ } ) ;
10299 writeFileSync (
103100 path . join ( __dirname , 'templates.js' ) ,
104101 `
105- const { gunzipSync } = require('zlib');
106- const buffer = gunzipSync (
102+ const { brotliDecompressSync } = require('zlib');
103+ const buffer = brotliDecompressSync (
107104 Buffer.from(
108105 '${ buffer . toString ( 'base64' ) } ',
109106 'base64'
@@ -114,6 +111,22 @@ export function generateCompressedTemplates<
114111 ) ;
115112}
116113
114+ export function generateCompressedTemplates <
115+ TPage extends string = HttpServerPage
116+ > (
117+ pages : Record <
118+ TPage ,
119+ {
120+ Component : Component ;
121+ parameters : string [ ] ;
122+ }
123+ >
124+ ) : void {
125+ const templates = JSON . stringify ( generateTemplates ( pages ) ) ;
126+ generateGzip ( templates ) ;
127+ generateJS ( templates ) ;
128+ }
129+
117130if ( require . main === module ) {
118131 generateCompressedTemplates ( {
119132 [ HttpServerPage . OIDCErrorPage ] : {
0 commit comments