On 13 déc, 12:30, Michael <[email protected]> wrote: > Hi, > > This is a very naive question which I haven't found a clear answer to. > I've been building a GWT app, and have used CssResource for style. > Initially, I created a bunch of ClientBundle interfaces corresponding > to smaller widgets in the app, as well as a "global" interface for > very general, common resources (similar to the global GWT stylesheet). > However, the more the app was growing, the more lazy I've become in > the sense that I've started putting everything in the global > resources, in order not to have a billion ClientBundle interfaces > (together with initialization code, style injection code, and yet > another css file). My question is thus: is putting all style in a > global resource a bad practice?
My experience says that it hurts maintainability. In our "legacy" app we had a single global Messages interface. The problem now is that when wee need to change a label somewhere, we first have to check whether other uses of the same message were really similar or just the result of a lazy programmer reusing an identical label despite having different meanings (e.g. "orange" the color, vs. "orange" the fruit). We've now started a new app from scratch, using all GWT 2.0 new goodness, and I think we'll soon start being lazy the other way around: keeping everything near where it's used and not refactoring CssResource, Messages, etc. to try to share things. So I believe both approaches have their pros and cons. > I am asking both design- and > performance-wise. By default, in all browsers but IE6/7, GWT inlines resources in the JS code (using data: URIs), so the stylesheets are downloaded at the very same time as the JS code. This means using one or several CssResources shouldn't have a big impact on code size (hence network perfs). Well, until you start using code splitting too; in this case, I'd expect (haven't verified) GWT to appropriately disseminating CssResources in the code fragment where they're needed, which isn't possible if you use a single big global CssResource. > For the latter, it is in fact quite unclear to me > what actually happens in the background when injecting style (style > ().ensureInjected()). Does such a call inject the entirety of the css, > or only the part that the widget needs? The whole CssResource is injected. > I think the GWT well explains > how to use CssResource in a single widget, but does not address the > question of when/how to break it up in a larger app. Hope this makes > sense and that you can clear it up for me! For now, we're using very local and specific CssResources (almost every widget or view –in the MVP sense– has its own CssResource, either explicit or through UiBinder), with some refactorings from time to time when something can/should be shared. We haven't yet done any measurement re. the impact on performance (and we're not yet using code splitting either). I believe GWT manages this (a lot of CssResources) very well. I also believe though that there's not a single practice to rule them all (just like resource inlining through data: URIs isn't always a perf gain): experiment and measure, as always. -- You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/google-web-toolkit?hl=en.
