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.md
pull/12415/head
Rick Anderson 2019-05-14 07:27:39 -10:00 committed by GitHub
parent 4976027a72
commit f603e04127
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 53 additions and 0 deletions

View File

@ -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)]

View File

@ -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
}