Preparing for Material Design transitions
Jul 24, 2019
In my last post, we optimized the images. By the way, Cloudinary seems to want to compress the images further and further (as I retested). I think it also never stops (just like me).
I mentioned Material Design in several posts before. More specifically, I mentioned Material Design Lite, which is an implementation of the Material Design principles. My main trigger for looking in this direction is that jQuery 3.3.1 has a moderate-severity security flaw. jQuery these days is a frowned-upon black sheep, and I don’t share this disdain: when suddenly there’s a new Kool-Aid and most people suddenly deny their past and exile well-established practices; in turn, many start to work with VanillaJS and don’t realize that they are actually reimplementing their own pathetic, broken jQuery derivative (as if dozens of experienced jQuery contributors wouldn’t be smarter than them…). I’d be happy to minimize script and CSS resource sizes anytime, though. jQuery is a dependency of Bootstrap 4, and the old version of the website used Bootstrap Native, which by definition is a Bootstrap derivative without a jQuery dependency. When I upgraded to Bootstrap 4, I needed to bring jQuery back in, and the only main feature this website uses jQuery for (besides Bootstrap using its capabilities) is to provide the menu drawer on mobile form factors. That’s admittedly a very narrow need. So the security vulnerability wouldn’t bother me much—this is a static website where it would not really matter—but it motivates me to pursue bandwidth optimization further.
I worked with Material Design Lite in multiple releases of the Hoverboard conference website project. You can tell if you work with MDL when you use mdl-*-shaped CSS classes. However, MDL is now superseded by Material Components for the web. Material Design in itself wouldn’t prompt me to move away from Bootstrap, by the way, because there are many Bootstrap spin-offs that apply Material Design out of the box. However, it shows me the possibility of minimizing bandwidth. I know that not only Material Design animations (for example, the click ripple effects), but possibly even the menu drawer could be implemented with pure CSS. Google engineering teams spent man-months (years?) optimizing those. So I see the potential to eliminate script resources entirely, or keep them extremely minimal. On the CSS side, MDC is modular, so I have the opportunity to cut down the fluff I don’t use. I should add that this is true for Bootstrap as well; Bootstrap’s SCSS is modular too (not surprisingly).
What does this mean in numbers?
- Currently: jQuery 3.3.1 min (69917) + BS 4 min JS (78635) + BS 4 min CSS (146304) + carousel min CSS (130) = 294986
- The late Material Design Lite: JS (62491) + CSS (139816) + for carousel let’s count mdl-ext’s JS (9700) + CSS (1249) = 213256
- Material Components for the web: JS (297455) + CSS (267528) = 564983
Now, 300K vs. 200K (without cherry-picking SCSS and JS) would be a nice reduction. MDC is over half a meg if we bundle everything up. However, after cherry-picking, I hope for a larger reduction than a 200K compound bundle; especially on the JavaScript front, I expect very minimal code. All of this is because before jumping headfirst into Material Components for the web, I wanted to evaluate these alternatives clearly. Right now, I think I’ll continue transitioning toward MDC and see where I end up on the optimization front. I may "cheat" by leaving out the large carousels.
I also need to account for the Material Icons fontset, which I’ll need to bring in and host, and that’s an additional increase over the bare jQuery + Bootstrap way. I read a Medium article that talked about a technique of cherry-picking individual glyphs out of icon fontsets with the help of the Fontello service, although Material Icons are not part of that service. I may dig deeper to see if this is possible for Material Icons. That Medium post also showed me other speed test websites. One of my main goals is to keep the uniqueness of the website as much as possible and not become too similar to other Material Design websites during this effort. Stay tuned for more Material Design progress and headless CMS posts.