← Back to Developer Tools

Code Minifier

Reduce your source code's file size by removing unnecessary whitespace and comments.

Input Code
Minified Output
Savings: 0%
const input = document.getElementById('input').value; const lang = document.getElementById('lang').value; let output = ''; if (lang === 'js') { // Simple JS minification (Regex based - NOT perfect, but client-side safe enough for basic needs) // Remove comments output = input.replace(/\/\*[\s\S]*?\*\/|([^\\:]|^)\/\/.*$/gm, '$1'); // Remove whitespace output = output.replace(/\s+/g, ' '); output = output.replace(/\s*([\{\}\[\]\(\);=,\+\-\*\/])\s*/g, '$1'); } else if (lang === 'css') { // CSS Minification output = input.replace(/\/\*[\s\S]*?\*\//g, ''); // Comments output = output.replace(/\s+/g, ' '); // Collapse space output = output.replace(/\s*([\{\};:,])\s*/g, '$1'); // Remove space around chars } else if (lang === 'html') { // HTML Minification output = input.replace(new RegExp('', 'g'), ''); output = output.replace(/\s+/g, ' '); output = output.replace(/>\s+<'); } output = output.trim(); document.getElementById('output').value = output; //t // Stats const originalSize = new Blob([input]).size; const newSize = new Blob([output]).size; const saved = originalSize > 0 ? ((originalSize - newSize) / originalSize * 100).toFixed(2) : 0; document.getElementById('stats').textContent = `Original: ${originalSize}B | Minified: ${newSize}B | Saved: ${saved}%`; } function copy() { navigator.clipboard.writeText(document.getElementById('output').value); }