optimize scripts
This commit is contained in:
parent
8cd6a72dd3
commit
d4da02318d
|
@ -40,7 +40,7 @@
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
<base href="/" />
|
<base href="/" />
|
||||||
<link rel="stylesheet" href="css/app.css" />
|
<link rel="stylesheet" href="css/app.css" />
|
||||||
@if (!string.IsNullOrEmpty(_PWAScript))
|
@if (_scripts.Contains("PWA Manifest"))
|
||||||
{
|
{
|
||||||
<link id="app-manifest" rel="manifest" />
|
<link id="app-manifest" rel="manifest" />
|
||||||
}
|
}
|
||||||
|
@ -74,9 +74,7 @@
|
||||||
<script src="js/loadjs.min.js"></script>
|
<script src="js/loadjs.min.js"></script>
|
||||||
<script src="js/interop.js"></script>
|
<script src="js/interop.js"></script>
|
||||||
|
|
||||||
@((MarkupString)_reconnectScript)
|
@((MarkupString)_scripts)
|
||||||
@((MarkupString)_PWAScript)
|
|
||||||
@((MarkupString)_scrollPositionScript)
|
|
||||||
@((MarkupString)_bodyResources)
|
@((MarkupString)_bodyResources)
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -101,9 +99,7 @@
|
||||||
private string _headResources = "";
|
private string _headResources = "";
|
||||||
private string _bodyResources = "";
|
private string _bodyResources = "";
|
||||||
private string _styleSheets = "";
|
private string _styleSheets = "";
|
||||||
private string _reconnectScript = ""; // for Interactive render mode and Blazor Server interactivity only
|
private string _scripts = "";
|
||||||
private string _PWAScript = ""; // for PWA apps only
|
|
||||||
private string _scrollPositionScript = ""; // for Static render mode only
|
|
||||||
private string _message = "";
|
private string _message = "";
|
||||||
private PageState _pageState;
|
private PageState _pageState;
|
||||||
|
|
||||||
|
@ -177,17 +173,18 @@
|
||||||
ManageStyleSheets(resources);
|
ManageStyleSheets(resources);
|
||||||
ManageScripts(resources, alias);
|
ManageScripts(resources, alias);
|
||||||
|
|
||||||
|
// generate scripts
|
||||||
if (_renderMode == RenderModes.Interactive && _runtime == Runtimes.Server)
|
if (_renderMode == RenderModes.Interactive && _runtime == Runtimes.Server)
|
||||||
{
|
{
|
||||||
_reconnectScript = CreateReconnectScript();
|
_scripts += CreateReconnectScript();
|
||||||
}
|
}
|
||||||
if (site.PwaIsEnabled && site.PwaAppIconFileId != null && site.PwaSplashIconFileId != null)
|
if (site.PwaIsEnabled && site.PwaAppIconFileId != null && site.PwaSplashIconFileId != null)
|
||||||
{
|
{
|
||||||
_PWAScript = CreatePWAScript(alias, site, route);
|
_scripts += CreatePWAScript(alias, site, route);
|
||||||
}
|
}
|
||||||
@if (_renderMode == RenderModes.Static)
|
@if (_renderMode == RenderModes.Static)
|
||||||
{
|
{
|
||||||
_scrollPositionScript = CreateScrollPositionScript();
|
_scripts += CreateScrollPositionScript();
|
||||||
}
|
}
|
||||||
|
|
||||||
_headResources += ParseScripts(site.HeadContent);
|
_headResources += ParseScripts(site.HeadContent);
|
||||||
|
@ -492,17 +489,18 @@
|
||||||
{
|
{
|
||||||
return
|
return
|
||||||
"<script>" + Environment.NewLine +
|
"<script>" + Environment.NewLine +
|
||||||
" window.interceptNavigation = () => {" + Environment.NewLine +
|
" // Static Blazor Scroll Position" + Environment.NewLine +
|
||||||
" let currentUrl = window.location.href;" + Environment.NewLine +
|
" window.interceptNavigation = () => {" + Environment.NewLine +
|
||||||
" Blazor.addEventListener('enhancedload', () => {" + Environment.NewLine +
|
" let currentUrl = window.location.href;" + Environment.NewLine +
|
||||||
" let newUrl = window.location.href;" + Environment.NewLine +
|
" Blazor.addEventListener('enhancedload', () => {" + Environment.NewLine +
|
||||||
" if (currentUrl != newUrl) {" + Environment.NewLine +
|
" let newUrl = window.location.href;" + Environment.NewLine +
|
||||||
" window.scrollTo({ top: 0, left: 0, behavior: 'instant' });" + Environment.NewLine +
|
" if (currentUrl != newUrl) {" + Environment.NewLine +
|
||||||
" }" + Environment.NewLine +
|
" window.scrollTo({ top: 0, left: 0, behavior: 'instant' });" + Environment.NewLine +
|
||||||
" currentUrl = newUrl;" + Environment.NewLine +
|
" }" + Environment.NewLine +
|
||||||
" });" + Environment.NewLine +
|
" currentUrl = newUrl;" + Environment.NewLine +
|
||||||
" };" + Environment.NewLine +
|
" });" + Environment.NewLine +
|
||||||
" document.onload += window.interceptNavigation();" + Environment.NewLine +
|
" };" + Environment.NewLine +
|
||||||
|
" document.onload += window.interceptNavigation();" + Environment.NewLine +
|
||||||
"</script>";
|
"</script>";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user