-
-
Notifications
You must be signed in to change notification settings - Fork 530
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Css-Cache for the ThemeGenerator #2103
Comments
It all depends on where the actual problem is. Does the generator takes too much time to build or does it takes slow to read HTML once the styles are loaded? I think I can easily cache the built styles. It's just a matter of few boolean flags. Hope it will help a little. |
@FStolte Are you sure we need caching? I'm testing to see how many times Blazor could re-render ThemeProvider and re-generate the theme and I found it only happens once on the app start. Later when I navigate to any page it still doesn't re-generate. Unless I specifically call |
I think you might've misunderstood me. In a single session, the generation only happens once in the beginning as you say. But it happens once for every session, so for everyone accessing the page, the first load is delayed. I was talking about caching the css across sessions in a singleton service, so that it ideally only needs to happen once each time the app is deployed (for Server-side Blazor, of course). |
Ahhh that. Well, it is working as expected. Remember, even if you have 100 users, one of those users can still choose to have a different theme color. That is, if you have a way to choosing a theme in your app. The only thing I can do is to maybe move a generator into a service class that can be injected through the DI. That way you could re-register it as singleton maybe. |
"even if you have 100 users, one of those users can still choose to have a different theme color" I understand that this might not be a priority for you, but would you be open to a PR from me about this topic? |
Let the code speaks for itself :) Yes, if possible open a new PR and we'll see how it goes. Don't forget to read our CONTRIBUTING https://github.com/stsrki/Blazorise/blob/master/CONTRIBUTING.md#branch-organization guidelines. |
We recently started using the Blazorise Theme in one of our projects to get our custom primary color into the Blazorise css (for the Stepper component). Now, we noticed a performance impact of using the Theme which slowed down initial site loading from about 600ms to 1.7s. This is on Server-side Blazor, btw.
Since likely most projects will only use a few different Themes, or even just one, I think it might be useful to implement a cache for the ThemeGenerator. If the same Theme is passed several times to the generator, it should not be necessary to generate the css again every time. If this performance impact is not just on our side, then a cache could bring a nice performance boost to the framework.
Of course this only really helps Server-side Blazor, since Blazor Webassembly would have to generate each Theme for each user once, anyway.
The text was updated successfully, but these errors were encountered: