AspnetJavascriptIsolation
1.0.0
This component allows you to associate a JavaScript file with an MVC view or a Razor page to isolate the JavaScript calls to that page only. If the file is present and is marked as "Content", the component automatically adds a script tag in the body with a link to this file.
Install the package from NuGet:
Install-Package AspnetJavascriptIsolation
In your csproj, add the following ItemGroup :
<ItemGroup>
<_JsIsolation Include="Pages***.cshtml.js" />
<DotNetPublishFiles Include="@(_JsIsolation)">
<DestinationRelativePath>%(Identity)</DestinationRelativePath>
</DotNetPublishFiles>
</ItemGroup>
Note: If you are using MVC, replace "Pages" by "Views" in the above code.
In your Program.cs before builder.Build(), add the following line:
builder.AddJavascriptIsolation(options =>
{
options.UseModule = true;
if (builder.Environment.IsProduction())
{
options.CacheDurationInHours = 24;
}
else
{
options.CacheDurationInHours = 0;
options.RootPath = builder.Environment.ContentRootPath;
}
});
If you using MVC configure the option :
options.RootFolder = "Views";
In your Program.cs, add the following line:
app.UseJavascriptIsolation();