Skip to content

Commit 21dfbfb

Browse files
authored
Load theme JavaScript module earlier from HTML (dotnet#4888)
1 parent 681f2e7 commit 21dfbfb

File tree

4 files changed

+10
-2
lines changed

4 files changed

+10
-2
lines changed

src/Aspire.Dashboard/Components/App.razor

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,5 +28,13 @@
2828
<Routes @rendermode="@(new InteractiveServerRenderMode(prerender: false))" />
2929
<script src="_framework/blazor.web.js"></script>
3030
<script src="js/app.js"></script>
31+
32+
@*
33+
Directly reference theme and dependencies from HTML so they load quickly.
34+
It's much faster to load them here than wait for module load from Blazor interop.
35+
Load time is important here because the theme should be applied ASAP.
36+
*@
37+
<script src="js/app-theme.js" type="module"></script>
38+
<script src="_content/Microsoft.FluentUI.AspNetCore.Components/Microsoft.FluentUI.AspNetCore.Components.lib.module.js" type="module"></script>
3139
</body>
3240
</html>

src/Aspire.Dashboard/Components/Dialogs/SettingsDialog.razor.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ protected override async Task OnAfterRenderAsync(bool firstRender)
4040
{
4141
if (firstRender)
4242
{
43-
_jsModule = await JS.InvokeAsync<IJSObjectReference>("import", "/js/theme.js");
43+
_jsModule = await JS.InvokeAsync<IJSObjectReference>("import", "/js/app-theme.js");
4444
_currentSetting = await _jsModule.InvokeAsync<string>("getThemeCookieValue");
4545
StateHasChanged();
4646
}

src/Aspire.Dashboard/Components/Layout/MainLayout.razor.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ protected override async Task OnAfterRenderAsync(bool firstRender)
113113
{
114114
if (firstRender)
115115
{
116-
_jsModule = await JS.InvokeAsync<IJSObjectReference>("import", "/js/theme.js");
116+
_jsModule = await JS.InvokeAsync<IJSObjectReference>("import", "/js/app-theme.js");
117117
_shortcutManagerReference = DotNetObjectReference.Create(ShortcutManager);
118118
_keyboardHandlers = await JS.InvokeAsync<IJSObjectReference>("window.registerGlobalKeydownListener", _shortcutManagerReference);
119119
ShortcutManager.AddGlobalKeydownListener(this);

0 commit comments

Comments
 (0)