Generate multiple CSS files for production, one per media #6904
Replies: 4 comments 2 replies
-
Any comments from tailwind maintainers? This would be a sick feature! |
Beta Was this translation helpful? Give feedback.
-
Definitely would be cool but definitely not a quick win and I don't even know if it's possible in a way that integrates nicely with other tools. For example there's no way for us to process one single CSS input file but somehow tell webpack to generate multiple CSS files and inject those There are existing plugins for this sort of thing depending on how your project works though: https://github.com/SassNinja/media-query-plugin |
Beta Was this translation helpful? Give feedback.
-
Beta Was this translation helpful? Give feedback.
-
To add to this discussion, the |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
This idea aims for small performance improvements regarding bundle sizes.
I understand that currently, Tailwind purposefully only generates one single CSS file for production, as highlighted in the Optimizing for Production section of the docs:
This is already pretty damn good and I basically agree with the general sentiment that this should be "good enough" for most cases. However, there is a possibility for further improvements:
The <link> HTML element, which lets you link to Tailwind's compiled CSS file, supports the media attribute:
Meaning, instead of linking to the the entire Tailwind file
it would be possible to link to multiple files, e.g.
With this, the user agent would load only the CSS that's currently needed.
Remix (a newly open sourced web framework, for those unaware) for example recommends this approach, and so does GoogleChromeLabs. As mentioned above, this certainly wouldn't skyrocket Tailwind's performance metrics. It'd be a rather small improvement. If anything, it'd appeal to folks who deeply care about performance and web standards, and could thus add a nice little touch to Tailwind.
Without knowing Tailwind's codebase, I would assume that this might be a quick win and not terribly much work. However, this probably should not be the default but something that sits behind a flag, so that it still holds true that users don’t have to worry about complex solutions if they don't want to.
Beta Was this translation helpful? Give feedback.
All reactions