2 minutes
How to Minify Compress Uglify Javascript
As you might have seen on the “How to: Minify CSS” article, minification helps speeding up websites.
The minification and therefor compression or in our case ‘uglification’ of JavaScript serves just the same purpose.
This would transform your JavaScript code form this
<div class="wp-block-codemirror-blocks-code-block code-block"><pre>var isFunction = function isFunction( obj ) {
// Support: Chrome <=57, Firefox <=52
// In some browsers, typeof returns "function"; for HTML <object> elements
// (i.e., `typeof document.createElement( "object" ) === "function"`).
// We don't want to classify *any* DOM node as a function.
return typeof obj === "function" && typeof obj.nodeType !== "number";
};
var isWindow = function isWindow( obj ) {
return obj != null && obj === obj.window;
};
var preservedScriptAttributes = {
type: true,
src: true,
noModule: true
};
function DOMEval( code, doc, node ) {
doc = doc || document;
var i,
script = doc.createElement( "script" );
script.text = code;
if ( node ) {
for ( i in preservedScriptAttributes ) {
if ( node[ i ] ) {
script[ i ] = node[ i ];
}
}
}
doc.head.appendChild( script ).parentNode.removeChild( script );
}
function toType( obj ) {
if ( obj == null ) {
return obj + "";
}
// Support: Android <=2.3 only (functionish RegExp)
return typeof obj === "object" || typeof obj === "function" ?
class2type[ toString.call( obj ) ] || "object" :
typeof obj;
}
to this
var isFunction=function(e){return"function"==typeof e&&"number"!=typeof e.nodeType},isWindow=function(e){return null!=e&&e===e.window},preservedScriptAttributes={type:!0,src:!0,noModule:!0};function DOMEval(e,t,n){var o,r=(t=t||document).createElement("script");if(r.text=e,n)for(o in preservedScriptAttributes)n[o]&&(r[o]=n[o]);t.head.appendChild(r).parentNode.removeChild(r)}function toType(e){return null==e?e+"":"object"==typeof e||"function"==typeof e?class2type[toString.call(e)]||"object":typeof e}
where I just used https://skalman.github.io/UglifyJS-online for ‘uglifying’ jQuery code.
Many tools are out there and I want to mention PHPStorm watchers as well as UglifyJS for good results.