I do not necessarily know how BundleTransformer instantiates the YuiJsMinifier class, but if it instantiates a single instance and uses it for the lifetime of the application then I have found an issue with the way the BundleTransformer.Yui minifier works.
Assuming that there is a single YuiJsMinifier instance shared for the lifetime of the application, it causes random errors to occur in multi-threaded applications (such as Asp.Net WebForms and Asp.Net MVC when multiple users are visiting the site at the same time). This is because the Yui library's JavaScriptCompressor class is not thread-safe itself.
A simple test case to prove Yui.Net's library isn't thread-safe:
```
using System;
using System.Linq;
using System.Threading.Tasks;
using Yahoo.Yui.Compressor;
namespace YuiBugConsole
{
public class YuiBug
{
public static void Main(string[] args)
{
var jsCompressor = new JavaScriptCompressor();
Parallel.ForEach(Enumerable.Range(1, 1000), (i) => {
jsCompressor.Compress(@"(function() { alert('a'); })();");
});
}
}
}
```
A simple way to fix this is to wrap the calls to "_jsCompressor.Compress" in BundleTransformer.Yui/Minifiers/YuiJsMinifier.cs with a lock to prevent more than one thread from compressing at the same time.
I would be surprised if Yui was the only minifier (css or js) that has this issue.
Comments: Hello, Brandon! Thanks for information. I will fix this bug in the next release.
Assuming that there is a single YuiJsMinifier instance shared for the lifetime of the application, it causes random errors to occur in multi-threaded applications (such as Asp.Net WebForms and Asp.Net MVC when multiple users are visiting the site at the same time). This is because the Yui library's JavaScriptCompressor class is not thread-safe itself.
A simple test case to prove Yui.Net's library isn't thread-safe:
```
using System;
using System.Linq;
using System.Threading.Tasks;
using Yahoo.Yui.Compressor;
namespace YuiBugConsole
{
public class YuiBug
{
public static void Main(string[] args)
{
var jsCompressor = new JavaScriptCompressor();
Parallel.ForEach(Enumerable.Range(1, 1000), (i) => {
jsCompressor.Compress(@"(function() { alert('a'); })();");
});
}
}
}
```
A simple way to fix this is to wrap the calls to "_jsCompressor.Compress" in BundleTransformer.Yui/Minifiers/YuiJsMinifier.cs with a lock to prevent more than one thread from compressing at the same time.
I would be surprised if Yui was the only minifier (css or js) that has this issue.
Comments: Hello, Brandon! Thanks for information. I will fix this bug in the next release.