js、css、html压缩与混淆汇总
背景
js混淆
const JO = require("javascript-obfuscator");
const code = `
function add(first, second) { return first + second; };
var v = add(1,2);
console.log(v);
`;
const result = JO.obfuscate(code,
{
compact: false,
controlFlowFlattening: true,
controlFlowFlatteningThreshold: 1,
numbersToExpressions: true,
simplify: true,
shuffleStringArray: true,
splitStrings: true,
stringArrayThreshold: 1,
}
);
console.log("混淆结果:", result.getObfuscatedCode())

js压缩
const { minify } = require("terser");
const code = `
function add(first, second) { return first + second; };
var v = add(1,2);
console.log(v);
`;
const result = await minify(code);
console.log("压缩结果:", result.code)
function add(d,n){return d+n}var v=add(1,2);console.log(v);
css压缩
const CleanCSS = require('clean-css');
const input = `
a {
font-weight:bold;
}
.vb {
border: 1px silid red;
}
`;
const options = { /* options */ };
const output = new CleanCSS(options).minify(code);
console.log("压缩结果:", output.styles)
a{font-weight:700}.vb{border:1px silid red}
html压缩

const htmlMinify = require("html-minifier").minify
const result = htmlMinify(htmlCode, {
minifyCSS: true,// 压缩css
minifyJS: true,// 压缩js
collapseWhitespace: true,// 删除html里的空格 达到html的压缩
removeAttributeQuotes: true,// 尽可能删除html标签里的双引号 达到html的压缩
removeComments: true, //删除html中的注释
removeCommentsFromCDATA: true, //从脚本和样式删除的注释
});
console.log("压缩结果:", result)
<html><head><style>a{font-weight:700}.vb{border:1px silid red}</style></head><body><div class=foreword>小蝌蚪,嘻嘻</div><script type=text/javascript>function add(d,n){return d+n}var v=add(1,2);console.log(v)</script></body></html>
结尾


关注公众号:拾黑(shiheibook)了解更多
赞助链接:
关注数据与安全,洞悉企业级服务市场:https://www.ijiandao.com/
四季很好,只要有你,文娱排行榜:https://www.yaopaiming.com/
让资讯触达的更精准有趣:https://www.0xu.cn/

随时掌握互联网精彩
- 微博热搜上线暖新闻机制 加大正能量内容扶持
- 【杂谈快报】淘宝首页上线 99 特卖频道;传字节跳动2022年收入增长30% 超800亿美元
- 捷报频传:统信UOS系列教材获奖、重磅新书上市!
- 2022年度中国科技风云榜·品牌荣耀 | 消费者选择品牌
- 麦肯锡:2025年中国公有云市场规模将达900亿美元
- 15元的影视会员成历史!头部平台全涨了
- 国潮点心,流量明星?
- 零点有数董事长袁岳:算法产业化势在必行
- 记录春节温馨瞬间,这几部索尼相机很适合
- iPhone 12s配置细节曝光,Redmi K40或有两个版本可选
- 统信UOS服务器操作系统 V20 欧拉版(1010)发布
- 统信发布UOS V20 进军个人市场 生态日益完善
赞助链接