πŸ› οΈToolsShed

Minifier JavaScript

Minifikasi JavaScript dengan menghapus komentar dan spasi untuk mengurangi ukuran file.

Pertanyaan yang Sering Diajukan

Implementasi Kode

# 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.