Building A MDC Web App With Only The Parts I Need

To avoid this problem, MDC Web (Material Design Components for Web) is designed so projects could pull in features piecemeal. Now each web app only has to download the parts they needed. The reason this isn't typically done is because of another inefficiency: there is overhead per HTTP transaction so we can't have MDC web components come down in tiny little individual pieces - the overhead would easily wipe out any space savings.
To avoid that problem, MDC Web uses webpack to bundle all the individual pieces into a consolidated file that only requires a single HTTP download transaction. So instead of a HTML file demanding tens to hundreds of individual CSS and JavaScript files, we have a single HTML file, that loads a single bundled CSS file, and a single bundled JavaScript file. These bundles are standalone pieces that can be served by any web server independent of MDC Web webpack infrastructure. Maybe even copied to a rover.
I was looking forward to this functionality and was happy to see it was covered in Section 5 of the Getting Started guide. After putting in the configuration required, it was a matter of typing npm run build
to generate my compact representation. I copied the generated bundle.css
and bundle.js
files and my index.html
to a separate directory for the next test.
When I served up my Getting Started project via the development server npm start
, Chrome developer console showed that the simple button required downloading 462KB of support files. That's roughly the same order of magnitude as what it would take to download Materialize and all supporting information, and I was eager to see improvement.
I then went to the separate directory with the built bundles. To ensure that I'm indeed free from npm and webpack, I served these bundle files using an entirely different infrastructure: Python 3's development web server. The environment variables $PORT and $IP were already set for a Cloud 9 environment and were reused:
python3 -m http.server $PORT --bind $IP
In the browser developer console, I could see that these files - and only these files - were downloaded. They added up to 32KB which was larger than I had hoped for in such a simple example, but maybe there's room for further optimization. In any case, that's definitely a tremendous improvement over 462KB.