Support » Plugin: Autoptimize » Optimizing Minimized JavaScript

  • A variety of JavaScript minimizers (also called compressors) are available and some have selectable degrees of minimization. The safest method is to simply remove unnecessary white-space, line-end-characters, and comments without making actual script code changes, but greater degrees of minimization usually are possible with more aggressive methods where script code is changed in various ways to make it more compact. Some aggressive methods result in code that runs in web browsers, but that violates one or more JavaScript language rules.

    WordPress plugin authors often include JavaScript code that already has been minimized. Where it has been minimized by a minimizer that produces valid JavaScript code, either the built-in PHP or external YUI JavaScript compression capabilities in Autoptimize generally produce valid results. The optimized code may or may not be smaller than the original, depending on the minimization method previously used, but regardless, the resulting code usually runs fine in web browsers. However, where plugin authors include JavaScript code that has been minimized by an aggressive method that produces code that violates one or more JavaScript language rules, Autoptimize optimization may not produce usable code.

    As an example, I wrote a prettyPhoto WordPress plugin to meet my own needs. The original version of my plugin used the jquery.prettyPhoto.js 3.1.4 “production release” library. That version worked fine with or without Autoptimize JavaScript optimization. I recently upgraded my plugin to use the jquery.prettyPhoto.js 3.1.5 “production release” library. The upgraded plugin ran fine without Autoptimize optimization, but failed using either the PHP or YUI optimization options in Autoptimize. The problem was found to be that the “production release” of jquery.prettyPhoto.js 3.1.5 has been pre-optimized by an optimizer that produces code that violates JavaScript language rules. The solution was to include the uncompressed “development version” jquery.prettyPhoto.js 3.1.5 library instead.

    I have posted this only to explain one reason that the JavaScript code in some WordPress plugins cannot be successfully optimized by Autoptimize without plugin modification.

Viewing 1 replies (of 1 total)
  • Plugin Author Frank Goossens


    Great explanation, thanks admintiger.

    Instead of using the uncompressed dev version, you could also exclude prettyPhoto from being minimized in AO’s admin screen.

Viewing 1 replies (of 1 total)
  • The topic ‘Optimizing Minimized JavaScript’ is closed to new replies.