Forum Replies Created

Viewing 4 replies - 1 through 4 (of 4 total)
  • Thread Starter macorak

    (@macorak)

    Thank you very much for your response and for addressing the issue in dev build b21.

    Before your patch was available, we had already implemented a temporary fix to resolve the ="async" error that was causing console issues and affecting PageSpeed “Best Practices” scores.

    Our temporary fix inside the _js_defer() function looked like this:

    if (strpos($ori, ' async') !== false) {
        $ori = preg_replace('# async(?:=["\']async["'])?#is', '', $ori);
    }

    It worked well in practice, especially for the common case where async="async" was being injected, and helped us instantly restore 100/100/100/100 performance scores (especially on Chrome).

    After testing and reviewing your b21 patch:

    $ori = preg_replace('# async(?:=([\'"])(?:[^\1]+)\1)?#isU', '', $ori);

    —we want to say: this is a truly elegant and robust solution. 🙌
    It goes beyond simply removing async="async" and properly handles edge cases like async="xyz", with safe, regex-based enforcement of matching quote types. The use of the isU modifiers and non-greedy pattern is especially well thought out.

    Our solution was fast and functional, but yours is long-term, reliable, and production-ready.

    👏 Huge respect to your dev team for solving this the right way.

    We’ll be switching to your implementation as soon as b21 becomes stable and publicly released.

    Thanks again for your support and excellent work.

    Best regards,
    FENIX TEAM
    🔥🛠️🕊️

    • This reply was modified 9 months ago by macorak.
    Thread Starter macorak

    (@macorak)

    Hi @litetim,

    Thank you so much — your updated regex works well, but we’ve tested a slightly safer variant that includes a type check to prevent possible null assignment from preg_replace().

    We’re currently using this in production, and it works like a charm:

    if (strpos($ori, ‘ async’) !== false) {
    $new_ori = preg_replace(‘# async(?:=([\'”])(?:[^\1]+?)\1)?#is’, ”, $ori);
    if (is_string($new_ori)) {
    $ori = $new_ori;
    }
    }

    It gracefully handles any edge cases and prevents the “critical error” that may occur when preg_replace returns null.

    Here’s the full context inside _js_defer() in optimize.cls.php:

    private function _js_defer( $ori, $src ) {
    if (strpos($ori, ‘ async’) !== false) {
    $new_ori = preg_replace(‘# async(?:=([\'”])(?:[^\1]+?)\1)?#is’, ”, $ori);
    if (is_string($new_ori)) {
    $ori = $new_ori;
    }
    }

    if (strpos($ori, 'defer') !== false) {
        return false;
    }
    if (strpos($ori, 'data-deferred') !== false) {
        Debug2::debug2('[Optm] bypass: attr data-deferred exist');
        return false;
    }
    if (strpos($ori, 'data-no-defer') !== false) {
        Debug2::debug2('[Optm] bypass: attr api data-no-defer');
        return false;
    }
    
    return $ori;

    }

    🧠 Just for context, here’s a quick comparison between your proposed line and our currently used version:

    Your current (proposed) line:
    $ori = preg_replace(‘# async(?:=([\'”])(?:[^\1]+?)\1)?#is’, ”, $ori);

    • ✅ Uses elegant backreference with non-greedy quantifier — much better than the previous version
    • ❌ But has no safeguard against null return from preg_replace()
    • ⚠️ This caused a critical error on our site during implementation

    Our current production-safe version:
    if (strpos($ori, ‘ async’) !== false) {
    $new_ori = preg_replace(‘# async(?:=([\'”])(?:[^\1]+?)\1)?#is’, ”, $ori);
    if (is_string($new_ori)) {
    $ori = $new_ori;
    }
    }

    • ✅ Same effective regex
    • ✅ Adds a minimal is_string() check to prevent assignment of null
    • ✅ Already tested live on prokese.rs (WooCommerce, Shoptimizer, LiteSpeed + QUIC.cloud setup)

    Feel free to consider this safe fallback structure for your 7.3 release. We’d love to see it added so others don’t run into the same edge case.

    Thanks again for your amazing work — happy to contribute!
    🔥 Greetings from the Fenix team — powered by prokese.rs 💨

    Thread Starter macorak

    (@macorak)

    Dear litespeed team,

    i try solution but it break

    There has been a critical error on this website.

    Learn more about troubleshooting WordPress.

    i think better solution is this


    if (strpos($ori, ‘ async’) !== false) {
    $new_ori = preg_replace(‘# async(?:=[“\’]async[“\’])?#is’, ”, $ori);
    if (is_string($new_ori)) {
    $ori = $new_ori;
    }
    }
    i will test it now
    Best regards,
    Ljubomir (prokese.rs)

    Thread Starter macorak

    (@macorak)

    Dear LiteSpeed Team,

    🔍 We’ve submitted Report ID: IAFMJBMC

    Best regards,
    Ljubomir (prokese.rs)

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