electricitymaps / electricitymaps-contrib

A real-time visualisation of the CO2 emissions of electricity consumption
https://app.electricitymaps.com
GNU Affero General Public License v3.0
3.37k stars 908 forks source link

perf: Move CSS import to `main.tsx` #6890

Closed VIKTORVAV99 closed 1 week ago

VIKTORVAV99 commented 1 week ago

Issue

Since we didn't import the CSS in the same place as the other CSS files it created a separate bundle at build time. And since CSS is render blocking both where needed for the map to render.

Description

Moves the CSS import to our main.tsx where our other CSS imports are so they end up in the same bundle.

Initial testing shows some improvement in Lighthouse / PageSpeed Insights but the margins are not big enough to draw any significant conclusions.

Should also resolve: https://electricitymaps.sentry.io/issues/5029660668/?project=4504366922989568

[!NOTE] I did some experimenting and it seems like we can remove this entire import if we just create our own zoom buttons, everything else is working as expected without it. That should be significantly less code than the 63.75 kB we are bundling now and should not be render blocking. Created a linear issue for it here: AVO-342

Preview

On master:

dist/assets/MapWrapper-05820bd7.css               63.75 kB │ gzip:   9.07 kB
dist/assets/index-cfaab156.css                    76.15 kB │ gzip:  13.26 kB

On this branch:

dist/assets/index-4f5ad7ed.css                   139.90 kB │ gzip:  22.25 kB

Double check

VIKTORVAV99 commented 1 week ago

If we want to save a few kB on the css bundle we can also switch to https://lightningcss.dev as the minifier (it's as simple as adding the dependency and changing a single config option). There is no build cost to this, it's actually faster by 3-4x, but there would be another dependency to install.