Skip to content

Conversation

@snipervld
Copy link

At the moment, Asset.ExpandGlobs{:.c#} doesn't cache results of provider.GetAllFiles("/"), so in the following example (simplified example - in the real app, this bundle contains different globs at different nested levels):

builder
    .Services
    .AddWebOptimizer(
        pipeline =>
        {
            //...
            pipeline.AddJavaScriptBundle(
                "bundle1",
                "js/*",
                "js/*",
                "js/*",
                "js/*",
                "js/*",
                "js/*");
            //...
        },
        options =>
        {
            options.EnableTagHelperBundling = false;
        });

Asset.ExpandGlobs will get all files 6 times. It can be a problem, if the virtual files hierarchy is huge.

This PR caches the results of provider.GetAllFiles("/") per provider into HttpContext.Items dictionary.

Also, this fixes the case when many complex bundles are located on the same page, e.g.:

...
<script src="~/bundle1"></script>
<script src="~/bundle2"></script>
<script src="~/bundle3"></script>
...

Each of them will reuse the cached file hierarchy if possible.

P.S. As you can see, I've tested this with EnableTagHelperBundling = false. ScriptTagHelper and LinkTagHelper call Asset.ExpandGlobs on each execution, which resulted in 5 seconds of rendering for just the script tags in my app, instead of something like ~0.1 seconds. :)

@jzabroski
Copy link
Contributor

This should be re-worked to use GlobbingUrlBuilder - It internally uses a Cache and is backed by the full faith, credit and trust of ASP.NET Core :D

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants