diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 214bd19..988dc91 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -628,7 +628,7 @@ jobs: - name: Build rayhunter-daemon openapi docs run: | mkdir -p daemon/web/build - touch daemon/web/build/{favicon.png,index.html.gz,rayhunter_orca_only.png,rayhunter_text.png} + touch daemon/web/build/{favicon.png,index.html.br,rayhunter_orca_only.png,rayhunter_text.png} cargo run --bin gen_api --features apidocs -- ./rayhunter-openapi.json - name: Make swagger folder run: | diff --git a/daemon/src/server.rs b/daemon/src/server.rs index b442238..199c75e 100644 --- a/daemon/src/server.rs +++ b/daemon/src/server.rs @@ -112,9 +112,9 @@ pub async fn serve_static( "index.html" => ( [ (header::CONTENT_TYPE, HeaderValue::from_static("text/html")), - (header::CONTENT_ENCODING, HeaderValue::from_static("gzip")), + (header::CONTENT_ENCODING, HeaderValue::from_static("br")), ], - include_bytes!("../web/build/index.html.gz"), + include_bytes!("../web/build/index.html.br"), ) .into_response(), path => { diff --git a/daemon/web/package.json b/daemon/web/package.json index 05d903a..28d3c55 100644 --- a/daemon/web/package.json +++ b/daemon/web/package.json @@ -4,7 +4,7 @@ "type": "module", "scripts": { "dev": "vite dev", - "build": "vite build && gzip -9 ./build/index.html", + "build": "vite build && node ./scripts/compress-index.js", "preview": "vite preview", "check": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json", "check:watch": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json --watch", diff --git a/daemon/web/scripts/compress-index.js b/daemon/web/scripts/compress-index.js new file mode 100644 index 0000000..99e4200 --- /dev/null +++ b/daemon/web/scripts/compress-index.js @@ -0,0 +1,11 @@ +import { readFileSync, writeFileSync, unlinkSync } from 'node:fs'; +import { brotliCompressSync, constants } from 'node:zlib'; + +const input = './build/index.html'; +const output = './build/index.html.br'; + +const compressed = brotliCompressSync(readFileSync(input), { + params: { [constants.BROTLI_PARAM_QUALITY]: constants.BROTLI_MAX_QUALITY }, +}); +writeFileSync(output, compressed); +unlinkSync(input);