Homepage CO₂ first-load badge¶
Status: delivered (2026-08-27)
Branch: feat/673-impactconsumption-of-webapp
Show the webapp's own carbon footprint as a small badge + tooltip on the
homepage, computed once at build time. No Lighthouse involvement; the nightly
lighthouse.yml cron is untouched.
Decision¶
- Build-time constant, not live measurement. The SPA build emits a tiny
dist/spa/index.htmlbootstrap plus content-hashed chunks, so "weight of a visit" = index.html + the first-load assets it references (entry module script,modulepreloadchunks, stylesheets). - Per-byte constant from websitecarbon.com (
1.94e-7g CO₂/byte), overridable viaCO2_G_PER_BYTE. - First-load semantics: copy says the number is the first, uncached load; later visits are served from cache.
- No silent fallback: missing meta tag (dev server) → no badge rendered.
Shipped¶
frontend/scripts/inject-co2.mjs— post-build: gzips (level 9) index.html + referenced first-load assets, adds the raw size of every woff2 font those preload or reference (woff2 is already compressed), sums bytes, injects an idempotent<meta name="co2-first-load" content="{mg}|{kb}">, logs a one-line report. Missing referenced asset or missing</head>throws.frontend/quasar.config.js—build.afterBuildrunsscripts/inject-co2.mjs, so everyquasar build(npm script, Makefile, Docker, CI, or typed directly) carries the meta.frontend/src/composables/useCo2FirstLoad.ts— parses the meta tag, returns rounded{ mg, kb }ornull.frontend/src/components/organisms/workspace-selector/WorkspaceSelectorBar.vue— borderless green leaf-icon text +q-tooltipon the same row as the RoleAccessBadge, separated by a thin vertical rule; rendered only when the composable returns a value. The affiliation breadcrumb stays below that row. (Bar is used on the homepage only.)frontend/src/i18n/home.ts—home_co2_badge_label/home_co2_tooltip(EN/FR).frontend/quasar.config.js— dev-only Vite hook (apply: 'serve') copies the co2-first-load meta fromdist/spa/index.htmlinto the dev server's HTML, so the badge is also visible underquasar dev(with the number from the last production build). No dist or no meta → nothing injected.frontend/Makefile—make devrunsnpm run buildonce whendist/spa/index.htmlhas no co2-first-load meta, so the badge shows on a fresh checkout without a manual build.
Caveats¶
- Counts what index.html references (entry + preloads + CSS) plus the woff2
fonts preloaded from index.html or declared in the first-load CSS (Suisse
Intl ×3, Material Icons, Material Icons Outlined); excludes
injectEnv.jsand the lazily-loaded route chunks. The HomePage route's own lazy chunk is small; adding it later means also summingHomePage-[hash].{js,css}. - Suisse Intl comes from enac-it-fonts.epfl.ch since 2026-10-28, so it is
not in
dist/spa:inject-co2.mjscounts it from a table of served sizes and throws on an external font it does not list. - With fonts (2026-09-02): 574.9 KB across 47 files + 5 fonts (328.9 KB of which are fonts) → ≈114 mg CO₂ per first load.