Ejemplo n.º 1
0
        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)}");
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Creates a JavaScript bundle on the specified route and minifies the output.
 /// </summary>
 public static IAsset AddJavaScriptBundle(this IAssetPipeline pipeline, string route, params string[] sourceFiles)
 {
     return(pipeline.AddJavaScriptBundle(route, new CodeSettings(), sourceFiles));
 }