diff --git a/package-lock.json b/package-lock.json index 12bb7a348c6a..a053704ab6e0 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9548,6 +9548,15 @@ "@types/node": "*" } }, + "node_modules/@types/compression": { + "version": "1.7.5", + "resolved": "https://registry.npmjs.org/@types/compression/-/compression-1.7.5.tgz", + "integrity": "sha512-AAQvK5pxMpaT+nDvhHrsBhLSYG5yQdtkaJE1WYieSNY2mVFKAgmU4ks65rkZD5oqnGCFLyQpUr1CqI4DmUMyDg==", + "dev": true, + "dependencies": { + "@types/express": "*" + } + }, "node_modules/@types/connect": { "version": "3.4.38", "resolved": "https://registry.npmjs.org/@types/connect/-/connect-3.4.38.tgz", @@ -36264,7 +36273,9 @@ "devDependencies": { "@angular-builders/custom-webpack": "16.0.1", "@nguniversal/builders": "16.2.0", + "@types/compression": "1.7.5", "@types/express": "4.17.21", + "compression": "1.7.4", "express": "4.19.2", "terser-webpack-plugin": "5.3.10" } diff --git a/projects/demo/package.json b/projects/demo/package.json index 1fc8e616d317..1b0d36b9e0f2 100644 --- a/projects/demo/package.json +++ b/projects/demo/package.json @@ -22,7 +22,9 @@ "devDependencies": { "@angular-builders/custom-webpack": "16.0.1", "@nguniversal/builders": "16.2.0", + "@types/compression": "1.7.5", "@types/express": "4.17.21", + "compression": "1.7.4", "express": "4.19.2", "terser-webpack-plugin": "5.3.10" } diff --git a/projects/demo/server.ts b/projects/demo/server.ts index 7b237a573cb5..b668860388ad 100644 --- a/projects/demo/server.ts +++ b/projects/demo/server.ts @@ -3,10 +3,12 @@ import 'zone.js/node'; import {existsSync} from 'node:fs'; import {join} from 'node:path'; +import * as zlib from 'node:zlib'; import {APP_BASE_HREF} from '@angular/common'; import {provideLocation, provideUserAgent} from '@ng-web-apis/universal'; import {ngExpressEngine} from '@nguniversal/express-engine'; +import compression from 'compression'; import express from 'express'; import bootstrap from './src/main.server'; @@ -31,6 +33,14 @@ if (moduleFilename === __filename || moduleFilename.includes('iisnode')) { const server = express(); const dist = join(process.cwd(), 'dist/demo/browser'); + server.use( + compression({ + level: 9, + memLevel: 9, + strategy: zlib.constants.Z_HUFFMAN_ONLY, + }), + ); + server.engine('html', ngExpressEngine({bootstrap})); server.set('view engine', 'html'); server.set('views', dist);