/// <summary> /// Produces a code minifiction of JS content by using the YUI JS Compressor for .NET /// </summary> /// <param name="content">JS content</param> /// <param name="isInlineCode">Flag whether the content is inline code</param> /// <param name="encoding">Text encoding</param> /// <returns>Minified JS content</returns> public CodeMinificationResult Minify(string content, bool isInlineCode, Encoding encoding) { if (string.IsNullOrWhiteSpace(content)) { return new CodeMinificationResult(string.Empty); } string newContent = string.Empty; var errors = new List<MinificationErrorInfo>(); var warnings = new List<MinificationErrorInfo>(); var errorReporter = new YuiJsErrorReporter(); lock (_minificationSynchronizer) { _originalJsMinifier.ErrorReporter = errorReporter; _originalJsMinifier.Encoding = encoding; try { newContent = _originalJsMinifier.Compress(content); } catch (EcmaScriptRuntimeException e) { errors.Add(new MinificationErrorInfo(e.Message, e.LineNumber, e.ColumnNumber, e.LineSource)); } catch (EcmaScriptException e) { errors.Add(new MinificationErrorInfo(e.Message, e.LineNumber, e.ColumnNumber, e.LineSource)); } finally { _originalJsMinifier.ErrorReporter = null; _originalJsMinifier.Encoding = Encoding.Default; } } errors.AddRange(errorReporter.Errors); warnings.AddRange(errorReporter.Warnings); return new CodeMinificationResult(newContent, errors, warnings); }
/// <summary> /// Produces code minifiction of JS content by using /// YUI JS Compressor for .NET /// </summary> /// <param name="content">JS content</param> /// <param name="isInlineCode">Flag whether the content is inline code</param> /// <param name="encoding">Text encoding</param> /// <returns>Minified JS content</returns> public CodeMinificationResult Minify(string content, bool isInlineCode, Encoding encoding) { if (string.IsNullOrWhiteSpace(content)) { return new CodeMinificationResult(string.Empty); } var errors = new List<MinificationErrorInfo>(); var warnings = new List<MinificationErrorInfo>(); var errorReporter = new YuiJsErrorReporter(); var jsCompressor = CreateJavaScriptCompressorInstance(); jsCompressor.ErrorReporter = errorReporter; jsCompressor.Encoding = encoding; string newContent = string.Empty; try { newContent = jsCompressor.Compress(content); } catch (EcmaScriptRuntimeException e) { errors.Add(new MinificationErrorInfo(e.Message, e.LineNumber, e.ColumnNumber, e.LineSource)); } catch (EcmaScriptException e) { errors.Add(new MinificationErrorInfo(e.Message, e.LineNumber, e.ColumnNumber, e.LineSource)); } errors.AddRange(errorReporter.Errors); warnings.AddRange(errorReporter.Warnings); return new CodeMinificationResult(newContent, errors, warnings); }