.Net Core HTML/JS/CSS 静态文件压缩方案,YUICompressor.NET
一、 .Net Core HTML 压缩
使用正则去除多余换行和空格
string filename = AppDomain.CurrentDomain.BaseDirectory + "default.1.html"; string content = File.ReadAllText(filename); //执行html压缩,此方法忽略 style,script标签之间内容 content = Regex.Replace(content, @"\s+(?=<)|\s+$|(?<=>)\s+", ""); Console.WriteLine(content);
二、.Net Core YUICompressor.NET 实现JavaScript压缩,css压缩
1.安装 工具库
Install-Package YUICompressor.NET
2.使用 JavaScriptCompressor压缩js代码
string filename = AppDomain.CurrentDomain.BaseDirectory + "SliderBar5.0.js"; string content = File.ReadAllText(filename); //执行js压缩 JavaScriptCompressor jsCom = new JavaScriptCompressor(); content = jsCom.Compress(content); Console.WriteLine(content);
3.使用 CssCompressor 压缩css代码
string filename = AppDomain.CurrentDomain.BaseDirectory + "SliderBar5.0.css"; string content = File.ReadAllText(filename); //执行css压缩 CssCompressor cssCom = new CssCompressor(); content = cssCom.Compress(content); Console.WriteLine(content);
更多:
C#Css/Js静态文件压缩--Yui.Compressor.Net
C# ZXing.Net生成二维码、识别二维码、生成带Logo的二维码(二)