update Author TH (#12394)
* update Author TH * update Author TH * update Author TH * update Author TH * update Author TH * Update aspnetcore/mvc/views/tag-helpers/authoring.md Co-Authored-By: reZach <reZach@users.noreply.github.com> * Update aspnetcore/mvc/views/tag-helpers/authoring.md Co-Authored-By: Luke Latham <1622880+guardrex@users.noreply.github.com> * Update authoring.mdpull/12415/head
parent
4976027a72
commit
f603e04127
|
@ -307,3 +307,12 @@ The tag helpers provide several properties to retrieve content.
|
|||
[!code-csharp[](../../views/tag-helpers/authoring/sample/AuthoringTagHelpers/src/AuthoringTagHelpers/TagHelpers/z1AutoLinkerCopy.cs?highlight=5,6,10&range=8-21)]
|
||||
|
||||
* Multiple calls to `GetChildContentAsync` returns the same value and doesn't re-execute the `TagHelper` body unless you pass in a false parameter indicating not to use the cached result.
|
||||
|
||||
## Load minified partial view TagHelper
|
||||
|
||||
In production environments, performance can be improved by loading minified partial views. To take advantage of minified partial view in production:
|
||||
|
||||
* Create/set up a pre-build process that minifies partial views.
|
||||
* Use the following code to load minified partial views in non-development environments.
|
||||
|
||||
[!code-csharp[](authoring/sample/AuthoringTagHelpers/src/MinifiedVersionTagHelper.cs?name=snippet)]
|
||||
|
|
|
@ -0,0 +1,44 @@
|
|||
using Microsoft.AspNetCore.Hosting;
|
||||
using Microsoft.AspNetCore.Mvc.TagHelpers;
|
||||
using Microsoft.AspNetCore.Mvc.ViewEngines;
|
||||
using Microsoft.AspNetCore.Mvc.ViewFeatures.Internal;
|
||||
using Microsoft.AspNetCore.Razor.TagHelpers;
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AuthoringTagHelpers.TagHelpers
|
||||
{
|
||||
/// <summary>
|
||||
/// The minified-partial tag helper loads
|
||||
/// minified partials depending on the value
|
||||
/// of ASPNETCORE_ENVIRONMENT.
|
||||
/// </summary>
|
||||
#region snippet
|
||||
public class MinifiedVersionPartialTagHelper : PartialTagHelper
|
||||
{
|
||||
public MinifiedVersionPartialTagHelper(ICompositeViewEngine viewEngine,
|
||||
IViewBufferScope viewBufferScope)
|
||||
: base(viewEngine, viewBufferScope)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public override Task ProcessAsync(TagHelperContext context, TagHelperOutput output)
|
||||
{
|
||||
// Append ".min" to load the minified partial view.
|
||||
if (!IsDevelopment())
|
||||
{
|
||||
Name += ".min";
|
||||
}
|
||||
|
||||
return base.ProcessAsync(context, output);
|
||||
}
|
||||
|
||||
private bool IsDevelopment()
|
||||
{
|
||||
return Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT")
|
||||
== EnvironmentName.Development;
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
}
|
Loading…
Reference in New Issue