From 895ac0997635653e82e9fb7785ebf19af5b41816 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alejandro=20Fern=C3=A1ndez?= <61871580+Alejandro-FA@users.noreply.github.com> Date: Sun, 13 Oct 2024 15:02:06 +0200 Subject: [PATCH] Fine-tune minification and remove unnecessary cache headers. --- lib/utils.dart | 1 + package.json | 7 ++++--- web/_headers | 16 ---------------- 3 files changed, 5 insertions(+), 19 deletions(-) diff --git a/lib/utils.dart b/lib/utils.dart index 9f05894..60817b8 100644 --- a/lib/utils.dart +++ b/lib/utils.dart @@ -53,6 +53,7 @@ enum MaterialWindowSizeClass implements Comparable { Future openWebpage(String url) async { final uri = Uri.parse(url); + assert(uri.scheme == 'https', 'URL must be secure'); if (!await launchUrl(uri)) { throw Exception('Could not launch $uri'); } diff --git a/package.json b/package.json index 055941d..10d7af4 100644 --- a/package.json +++ b/package.json @@ -20,8 +20,8 @@ "build:html": "flutter build web --no-pub --release --no-web-resources-cdn --web-renderer html", "build:wasm": "flutter build web --no-pub --release --no-web-resources-cdn --wasm", "build": "npm run build:${BUILD_RENDERER:-html}", - "postbuild:html": "npm run generate-sitemap -- -o build/web/sitemap.xml && npm run minify", - "postbuild:wasm": "npm run postbuild:html", + "postbuild:html": "npm run generate-sitemap -- -o build/web/sitemap.xml && npm run minify:js", + "postbuild:wasm": "npm run postbuild:html && npm run minify:mjs", "preserve:release": "npm run build", "serve:release": "dart run dhttpd --port ${npm_package_config_port} --path build/web/ --headersfile=build/web/_headers", "serve": "flutter run -d chrome", @@ -29,7 +29,8 @@ "deploy": "wrangler pages deploy build/web/ --branch=${DEPLOY_BRANCH} --project-name=${npm_package_name}", "generate-sitemap": "tsx scripts/generate_sitemap.ts lib/pages/*.dart --baseUrl ${npm_package_config_url}", "generate-routes": "dart run build_runner build", - "minify": "esbuild build/web/*.js --outdir=build/web/ --minify --format=esm --tree-shaking=true --allow-overwrite" + "minify:js": "esbuild 'build/web/**/*.js' --outdir=build/web/ --minify --tree-shaking=true --allow-overwrite", + "minify:mjs": "esbuild 'build/web/**/*.mjs' --outdir=build/web/ --minify --tree-shaking=true --allow-overwrite --out-extension:.js=.mjs" }, "repository": { "type": "git", diff --git a/web/_headers b/web/_headers index 45f2756..a9e201d 100644 --- a/web/_headers +++ b/web/_headers @@ -3,19 +3,3 @@ Content-Security-Policy: script-src 'sha256-jRFbZPGxmdoW0/Eufbok8i1mRwc8cgBguB60B/V1YeU=' 'strict-dynamic' 'wasm-unsafe-eval'; object-src 'none'; base-uri 'self'; Cross-Origin-Embedder-Policy: credentialless Cross-Origin-Opener-Policy: same-origin - -# Cache for 30 days -/icons/* - Cache-Control: public, max-age=2592000 - -/favicon.png - Cache-Control: public, max-age=2592000 - -/assets/* - Cache-Control: public, max-age=2592000, must-revalidate - -/canvaskit/* - Cache-Control: public, max-age=2592000, must-revalidate - -/manifest.json - Cache-Control: public, max-age=2592000, must-revalidate