123 points · by kkm · 5y ago · 70 comments
Is reducing the total amount of CSS per page so you don't have to calculate the critical CSS at all an option?
To throw my own page into the ring, here's a non-trivial product website of mine where the homepage is 0.3MB total over the wire and renders in 0.4 seconds for me (includes custom fonts, payments, analytics, large screenshot and real-time chat widget):
The major tricks I'm using is keeping the website CSS small (CSS for homepage + rest of site gzips to less than 8KB), inlining all CSS, rendering default fonts before the custom font has loaded, SVG for all images (this saves a ton), and not using JavaScript for content (which blocks rendering).
The screenshot in the header is in SVG format and inlined directly into the page along with the CSS, so the moment the HTML arrives the browser can display all above the fold content. Logos are another good one for the SVG + inline treatment.
Have you considered inlining CSS in the head (as you've done), but then serving it again with a linked css file just before </body>.
Then, with subsequent page loads (of the current or other pages), you don't have to inline any CSS anymore.
Of course this requires that you serve two versions of all your pages, one for if that page is a first hit, and another to be served to users who already have your CSS cached.
> You're gaining a great first impression at the cost of a poorer experience for every subsequent page load.
Yep, it's unfortunate we still have to make tradeoffs like this. At least in this case, it's less than 8KB added per page vs something more complicated that might break.
HTTP push was getting closer to offering some alternative like what you're suggesting (the server pushes the CSS file to the client in parallel to the initial HTML page, and the client can say if it already has the CSS file) but it's being deprecated now.
I believe that shaving a few additional kb from this already low number isn't worth the proposed complexity.
But this is a tradeoff that everybody has to decide for themselves.
If that's the argument, why not just let them take the (tiny) initial 8kb hit as an external css file, and make the rest of the experience even "zippier"?
The vast majority of users will visit one and only one page.
The big wins are: don't require JS for any content in the page header, use minimal CSS + inline it, strongly prefer SVG images over bitmaps + inline them, use "font-display: swap" + go easy with how many fonts you need.
Do you folks know the entertaining talk http://idlewords.com/talks/website_obesity.htm?
The main trick is to view your web app in a browser, print to PDF and then use Inkscape to auto convert from PDF -> SVG (with some caveats). Worst case you could recreate the screenshot from scratch in a vector editor.
The SVG icons are licensed from https://icons8.com/ (recommended!).
In my browser, I see 1.75 MB sent over the wire and a 2.5 second load time. My big pages of text [1] need 105 kB and load in 0.4 seconds. Their compressed critical CSS is the same size as my entire uncompressed CSS file. They send more CSS bytes than I send bytes in total.
If you want to make a content website fast, it's quite simple: send just the content.
[1] https://allaboutberlin.com/guides/german-health-insurance
FWIW, it does load in an instant for me. (Lighthouse Performance = 99, Speed Index = 0.4s.)
How do people come up with this shit?
- fonts can be unnecessarily huge
- monolithic js = slow. Chunk at build time.
- content-visibility: auto for lazy rendering
The e-commerce platform Magento 2 is packed with this kind of bullshit and is part of the reason my colleagues and I abandoned it for our clients' large e-commerce websites:
https://magento.stackexchange.com/questions/104583/magento-2...
https://old.reddit.com/r/Magento/comments/bli7vz/seriously_w...
https://magento.stackexchange.com/questions/277544/page-load...
https://magento.stackexchange.com/questions/270553/is-it-pos...
What's the first thing most people do when starting a new project? They ask "what framework should I build this on?" and start their tiny portfolio site built upon a massively overpowered suite of enterprise-level software with a million features they'll never, ever need.
Then they might drop in ten or fifteen separate external libraries because using vanilla HTML, CSS, and JavaScript is just "so 1995".
Then they start thinking about AJAX and microservices because rendering an entire page on the server side is utterly unthinkable in 2021.
Then they cram the site full of third-party services (because your tiny home-brew website will definitely benefit from Newrelic monitoring).
Then they might start on unit testing.
Finally they package everything up using at least seven different dependency managers, because a Github project without 100 useless ancillary files (grunt.js, app.yaml, travis.yml, composer.json, .gitignore, etc. etc.) is obviously not acceptable.
And this is why I hate modern web development.
Quite the opposite. It needs to be hammered into people. Your app isn't Notion or Google Docs. Your app is a form with a login menu and a couple of small logic elements and a date picker.
For myself, I would appreciate more such takes.
As a for instance you your script tag can just include a bunch of @import statements. Thankfully @import statements support media queries [0]. So you get the utility of external style sheets but can load one optimized for the client device. Unlike media queries on link tags the browser doesn't load style sheets (well they're not supposed to) that don't match the media queries.
It's also trivial to include a tiny bit of base styling with every page in a script tag. It doesn't blow any size budgets and makes sure a page is readable even with no external assets.
[0] https://developer.mozilla.org/en-US/docs/Web/CSS/@import
Sending reasonably well visually formated text is definitely a reasonable demand though.
OK, that basically describes any kind of software development, but web seems so much worse than anything else. And I say that as someone doing mainly Java backend development who's learned to live with the AbstractProxyFactoryManagerFactory jokes.
Nice write up but not a big surprise to anyone that blocks analytics tracking, ads, and third party embeds.