• I’m hitting a hard 500 caused by Autoptimize’s inline-JS minifier choking on modern JS (template literals) that an ad vendor injects inline.

    What breaks

    • Request to a post URL returns 500 when Optimize HTML code → “minify inline JS” is enabled (and/or “aggregate inline JS”).
    • The same URL loads fine with ?ao_noptimize=1 or after disabling inline-JS minify.

    Error (from Nginx/PHP-FPM logs)

    PHP Fatal error: Uncaught JSMin_UnterminatedStringException: JSMin: Unterminated String at byte 65907: `,e),window.adthriveCLS&&(window.adthriveCLS.injectedFromPlugin=!1)}}));Ni()})(); in /wp-content/plugins/autoptimize/classes/external/php/jsmin.php:212 Stack trace: #0 /wp-content/plugins/autoptimize/classes/external/php/jsmin.php(150): JSMin->action(1) #1 /wp-content/plugins/autoptimize/classes/external/php/jsmin.php(84): JSMin->min() #2 /wp-content/plugins/autoptimize/classes/external/php/ao-minify-html.php(257): JSMin::minify('(function(){win...') #3 [internal function]: AO_Minify_HTML->_removeScriptCB(Array) #4 /wp-content/plugins/autoptimize/classes/external/php/ao-minify-html.php(108): preg_replace_callback('/(\s*)(<script\...', Array, '...HTML...')

    Suspected culprit

    • Inline ad script referencing window.adthriveCLS (Raptive/AdThrive CLS helper) contains ES6 backticks or otherwise confuses JSMin.
    • JSMin (the embedded PHP version) doesn’t fully support ES2015+ grammar, so it throws UnterminatedStringException on template literals/backticks.
Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author ImageOptimizing Matters

    (@optimizingmatters)

    OK, have been looking into this for some time now (I like to avoid having to dive into JSMin to be honest) and the problem seems to be not with the template literals (which are taken care of by JSMin), but with a regex which results in JSMin ‘eating’ part of the JS and thereby removing part of the template .. :-/

    the offending code;
    C=y(e=>/Edge\/|Edg\//.test(e||S))

    specifically the double backslash in Edg\//

    still debugging (and not sure I’ll find a fix), but thought it best to at least already acknowledge the issue 😉

    best,
    frank

    Plugin Author ImageOptimizing Matters

    (@optimizingmatters)

    OK, the problem indeed is JSMin.php does not recognize the regex as being a regex and ends up removing part of the JS.

    I have a possible solution, but absolutely unsure if it is correct, so created a ticket at https://github.com/mrclay/jsmin-php/issues/23

    Thread Starter Imagejesusinica

    (@jesusinica)

    Last commit three years ago… Though the author, Steve, is still active on GitHub. Fingers crossed.

    Plugin Author ImageOptimizing Matters

    (@optimizingmatters)

    no such luck though. have you by any chance made the change yourself as a (wild) experiment? 🙂

Viewing 4 replies - 1 through 4 (of 4 total)

You must be logged in to reply to this topic.