dgp1130 / rules_prerender

A Bazel rule set for prerending HTML pages.
14 stars 0 forks source link

Better tree shaking for `prerender_multi_page_bundled()` CSS #27

Closed dgp1130 closed 2 years ago

dgp1130 commented 3 years ago

Spin off from #1.

Currently, prerender_multi_page_bundled() is somewhat suboptimal in generating bundled CSS. Every page declares some CSS files it needs, each of which imports its own graph of dependencies. However, all the CSS modules for every page are combined into a single entry point, which is then bundled by PostCSS. That singular bundle is then used for all generated HTML pages.

This means that if a single page imports module A, and no other page uses A, they will all still bundle A, download it, and apply it. This is additional bundle size which is not desirable or useful to users. It also means devs need to write their CSS to be conservative about content on the page, as it may be applied to unrelated pages. If styles are appropriately isolated, this won't have too much impact, but generic styles like p could totally break other pages they should never have been included with.

I believe this is a limitation of postcss_binary(), but I'll need to do some research to confirm. If so, we will likely need to make a FR to add support for accepting execution-time entry points.

dgp1130 commented 3 years ago

Finally got around to filing an issue with rules_postcss: https://github.com/bazelbuild/rules_postcss/issues/63

dgp1130 commented 2 years ago

I believe this is now obsolete given that global styles have been removed and all styles are inlined (#47). Since inlined styles are bundled at the component level, they are known at analysis time. There may be some build time benefit to delaying this work until the page is fully rendered and would run into this problem again, but I don't think this is an immediate problem to worry about.