I have a situation where I need to decide to include a html link based on client side boolean value and server side boolean value like this :
const preloadSupported = () => {
const link = document.createElement('link');
const relList = link.relList;
if (!relList || !relList.supports)
return false;
return relList.supports('preload');
};
if (!@Model.oldLayout && preloadSupported())
{
<link rel="preload" href="staticResource.js" as="script" />
}
or
if (@Model.oldLayout) //server side boolean
{
if (preloadSupported()) // client side boolean
{
@foreach (var url in Model.cssUrls)
{
<link rel="preload" href="@Html.StaticFile(url)" as="script"/>
}
}
else
{
@foreach (var url in Model.cssUrls)
{
<link rel="prefetch" href="@Html.StaticFile(url)"/>
}
}
}
how should I do that? I tried different variations none of them worked! thanks for your help in advance