JavaScript 压缩工具
通过删除注释和多余空白来压缩JavaScript。
常见问题
代码实现
# pip install jsmin
from jsmin import jsmin
js = """
// Utility functions for the application
function greet(name) {
/* Display greeting message */
const message = 'Hello, ' + name + '!';
console.log(message);
return message;
}
// Arrow function example
const add = (a, b) => {
return a + b;
};
// Class definition
class Calculator {
constructor() {
this.history = [];
}
// Add two numbers and store result
add(a, b) {
const result = a + b;
this.history.push(result);
return result;
}
}
"""
minified = jsmin(js)
print(minified)
original_size = len(js.encode("utf-8"))
minified_size = len(minified.encode("utf-8"))
print(f"Original: {original_size} bytes")
print(f"Minified: {minified_size} bytes")
print(f"Savings: {100 - minified_size / original_size * 100:.1f}%")Comments & Feedback
Comments are powered by Giscus. Sign in with GitHub to leave a comment.