From a27353a9f14722f4160c1c8873aac8b0fe2def5c Mon Sep 17 00:00:00 2001 From: Willian Galvani Date: Thu, 5 Feb 2026 12:29:30 -0300 Subject: [PATCH] Frontend: compress most files to .gz This saves about 75mb of image size --- core/frontend/package.json | 1 + core/frontend/vite.config.js | 9 +++++++++ core/tools/nginx/nginx.conf | 4 +++- 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/core/frontend/package.json b/core/frontend/package.json index 60ed95e129..6eec138bf2 100644 --- a/core/frontend/package.json +++ b/core/frontend/package.json @@ -94,6 +94,7 @@ "typescript": "~4.9.5", "unplugin-vue-components": "^0.25.2", "vite": "3", + "vite-plugin-compression": "^0.5.1", "vite-plugin-pwa": "^0.16.5", "vite-plugin-wasm": "^3.4.1", "vue-cli-plugin-vuetify": "~2.4.1", diff --git a/core/frontend/vite.config.js b/core/frontend/vite.config.js index e6198a7a2f..07da1c8a4c 100644 --- a/core/frontend/vite.config.js +++ b/core/frontend/vite.config.js @@ -4,6 +4,7 @@ import Components from 'unplugin-vue-components/vite' import { defineConfig, loadEnv } from 'vite' import { sentryVitePlugin } from "@sentry/vite-plugin"; import { VitePWA } from 'vite-plugin-pwa' +import viteCompression from 'vite-plugin-compression' import wasm from "vite-plugin-wasm" const { name } = require('./package.json') @@ -100,6 +101,14 @@ export default defineConfig(({ command, mode }) => { removeNonJson(repoPath) } }, + // Pre-compress assets with gzip for nginx to serve via gzip_static always + viteCompression({ + algorithm: 'gzip', + ext: '.gz', + threshold: 1024, + deleteOriginFile: true, + filter: /\.(js|css|json|svg|txt|xml|wasm|glb)$/i, + }), ], assetsInclude: ['**/*.gif', '**/*.glb', '**/*.png', '**/*.svg', '**/*.msg', "**/three/examples/jsm/libs/draco/*"], resolve: { diff --git a/core/tools/nginx/nginx.conf b/core/tools/nginx/nginx.conf index b4e70ddb35..9b83c83008 100644 --- a/core/tools/nginx/nginx.conf +++ b/core/tools/nginx/nginx.conf @@ -24,6 +24,9 @@ http { include /etc/nginx/mime.types; default_type application/octet-stream; + # Serve pre-compressed .gz files even without originals (requires client gzip support) + gzip_static always; + # Cache proxy_cache_path /var/cache/nginx keys_zone=ourcache:10m levels=1:2 max_size=1g inactive=30d; @@ -265,7 +268,6 @@ http { location /assets/ { root /home/pi/frontend; - try_files $uri $uri/; autoindex on; add_header Cache-Control "public, max-age=604800"; }