private void ProcessAsset(TagHelperOutput output) { if (string.IsNullOrEmpty(Src)) { return; } var urlHelper = UrlHelperFactory.GetUrlHelper(ViewContext); if (!urlHelper.IsLocalUrl(Src)) { output.Attributes.SetAttribute(SRC_ATTRIBUTE_NAME, Src); return; } //remove the application path from the generated URL if exists var pathBase = ViewContext.HttpContext?.Request?.PathBase ?? PathString.Empty; PathString.FromUriComponent(Src).StartsWithSegments(pathBase, out var sourceFile); if (!_assetPipeline.TryGetAssetFromRoute(sourceFile, out var asset)) { asset = _assetPipeline.AddJavaScriptBundle(sourceFile, sourceFile); } output.Attributes.SetAttribute(SRC_ATTRIBUTE_NAME, $"{Src}?v={asset.GenerateCacheKey(ViewContext.HttpContext)}"); }
public Task InvokeAsync(HttpContext context, IOptionsSnapshot <WebOptimizerOptions> options) { if (_pipeline.TryGetAssetFromRoute(context.Request.Path, out IAsset asset)) { _logger.LogRequestForAssetStarted(context.Request.Path); return(HandleAssetAsync(context, asset, options.Value)); } return(_next(context)); }
public Task InvokeAsync(HttpContext context, IOptionsSnapshot <WebOptimizerOptions> options) { string path = context.Request.Path.Value; if (context.Request.PathBase.HasValue) { path = path.TrimStart(context.Request.PathBase.Value.ToCharArray()); } if (_pipeline.TryGetAssetFromRoute(path, out IAsset asset)) { _logger.LogRequestForAssetStarted(context.Request.Path); return(HandleAssetAsync(context, asset, options.Value)); } return(_next(context)); }