Title: InvalidCharacterError: setAttribute &#8216;=&#8221;async&#8221;&#8216; bug in Gues
Last modified: July 8, 2025

---

# InvalidCharacterError: setAttribute ‘=”async”‘ bug in Gues

 *  Resolved [macorak](https://wordpress.org/support/users/macorak/)
 * (@macorak)
 * [10 months, 3 weeks ago](https://wordpress.org/support/topic/invalidcharactererror-setattribute-async-bug-in-gues/)
 * Hello LiteSpeed team,
 * We are experiencing a recurring error in the browser console caused by LiteSpeed
   Cache (v7.2), related to the delayed loading of JS:
 * InvalidCharacterError: Failed to execute ‘setAttribute’ on ‘Element’: ‘=”async”‘
   is not a valid attribute name.
 * 🔍 This happens when:
    - Guest Mode is ON
    - Guest Optimization is ON
    - Load JS Deferred / Delayed is enabled (but even when OFF, it can sometimes
      reappear)
    - QUIC.cloud optimizations are active (UCSS, VPI, Combine JS)
 * We’ve fully purged:
    - All caches (LSC + QUIC.cloud)
    - UCSS, Critical CSS, LQIP, VPI
    - Also disabled Delayed/Deferred scripts, but the error still shows up in certain
      guest views.
 * You can test the issue live here:
   👉 [https://prokese.rs/dugotrajna-platnena-kesa-za-usisivac-karcher-wd2/](https://prokese.rs/dugotrajna-platnena-kesa-za-usisivac-karcher-wd2/)
 * This is causing failing diagnostics in PageSpeed and browser console (especially
   Chrome and Firefox).
 * We believe the issue is due to litespeed_load_delayed_js() attempting to set 
   an attribute incorrectly:
   el.setAttribute(‘=”async”‘)
 * ✅ WordPress: 6.8.1
   ✅ LiteSpeed Cache: 7.2✅ WooCommerce + QUIC.cloud Page Optimization:
   ON
 * Please let us know if this is a known bug or if there’s a fix/workaround planned
   in upcoming releases. We love your plugin and just want to get rid of this console
   error completely.
 * Thank you in advance for your help!
 * – Ljubomir
   [https://prokese.rs](https://prokese.rs)

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

 *  Plugin Support [litetim](https://wordpress.org/support/users/litetim/)
 * (@litetim)
 * [10 months, 3 weeks ago](https://wordpress.org/support/topic/invalidcharactererror-setattribute-async-bug-in-gues/#post-18545460)
 * [@macorak](https://wordpress.org/support/users/macorak/) please share a report
   ID.
   Report can be created from LSC => Toolbox => Report => click on “Send to 
   Litespeed”Thank you for report, I have started debugging it and I need a bit 
   more info to continue.I identified something but I want to be sure.
 *  Thread Starter [macorak](https://wordpress.org/support/users/macorak/)
 * (@macorak)
 * [10 months, 3 weeks ago](https://wordpress.org/support/topic/invalidcharactererror-setattribute-async-bug-in-gues/#post-18546550)
 * Dear LiteSpeed Team,
 * 🔍 We’ve submitted Report ID: **IAFMJBMC**
 * Best regards,
   Ljubomir (prokese.rs)
 *  Plugin Support [litetim](https://wordpress.org/support/users/litetim/)
 * (@litetim)
 * [10 months, 3 weeks ago](https://wordpress.org/support/topic/invalidcharactererror-setattribute-async-bug-in-gues/#post-18546584)
 * [@macorak](https://wordpress.org/support/users/macorak/) 
   Let’s try this:In file`
   public_html/wp-content/plugins/litespeed-cache/src/optimize.cls.php` search for`'#
   async(?:=([\'"])(?:[^\1]+)\1)?#isU'` (aproximate line 1234) and replace with `'#
   async(?:=['"]async['"])?#is'`
 * This is not a final solution, take it as a test code, apply it on a stage site
   OR if you want on live: do it on your own risk.
 *  Thread Starter [macorak](https://wordpress.org/support/users/macorak/)
 * (@macorak)
 * [10 months, 3 weeks ago](https://wordpress.org/support/topic/invalidcharactererror-setattribute-async-bug-in-gues/#post-18546799)
 * Dear litespeed team,
 * i try solution but it break
 * There has been a critical error on this website.
 * [Learn more about troubleshooting WordPress.](https://wordpress.org/documentation/article/faq-troubleshooting/)
   
   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)
 *  Plugin Support [litetim](https://wordpress.org/support/users/litetim/)
 * (@litetim)
 * [10 months, 3 weeks ago](https://wordpress.org/support/topic/invalidcharactererror-setattribute-async-bug-in-gues/#post-18546817)
 * [@macorak](https://wordpress.org/support/users/macorak/) tell me the results 
   🙂
   Try this: `# async(?:=([\'"])(?:[^\1]+?)\1)?#is`The solution will be added
   to 7.3 🙂
 *  Thread Starter [macorak](https://wordpress.org/support/users/macorak/)
 * (@macorak)
 * [10 months, 3 weeks ago](https://wordpress.org/support/topic/invalidcharactererror-setattribute-async-bug-in-gues/#post-18546826)
 * Hi [@litetim](https://wordpress.org/support/users/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;}}
 *     ```wp-block-code
       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 💨
 *  Plugin Support [Hai Zheng⚡](https://wordpress.org/support/users/hailite/)
 * (@hailite)
 * [10 months, 3 weeks ago](https://wordpress.org/support/topic/invalidcharactererror-setattribute-async-bug-in-gues/#post-18546876)
 * Please try latest dev commit. Is is supposed to be fixed in b21.
 *  Thread Starter [macorak](https://wordpress.org/support/users/macorak/)
 * (@macorak)
 * [10 months, 3 weeks ago](https://wordpress.org/support/topic/invalidcharactererror-setattribute-async-bug-in-gues/#post-18546953)
 * 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:
 *     ```wp-block-code
       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:
 *     ```wp-block-code
       $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 10 months, 3 weeks ago by [macorak](https://wordpress.org/support/users/macorak/).
 *  Plugin Support [litetim](https://wordpress.org/support/users/litetim/)
 * (@litetim)
 * [10 months, 3 weeks ago](https://wordpress.org/support/topic/invalidcharactererror-setattribute-async-bug-in-gues/#post-18547184)
 * [@macorak](https://wordpress.org/support/users/macorak/) the fix will be added
   in 7.3 Please use that version for live sites.
   Version b21 is for test purposes
   only, we do not recommand using this on live server.

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

The topic ‘InvalidCharacterError: setAttribute ‘=”async”‘ bug in Gues’ is closed
to new replies.

 * ![](https://ps.w.org/litespeed-cache/assets/icon-256x256.png?rev=2554181)
 * [LiteSpeed Cache](https://wordpress.org/plugins/litespeed-cache/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/litespeed-cache/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/litespeed-cache/)
 * [Active Topics](https://wordpress.org/support/plugin/litespeed-cache/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/litespeed-cache/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/litespeed-cache/reviews/)

 * 9 replies
 * 3 participants
 * Last reply from: [litetim](https://wordpress.org/support/users/litetim/)
 * Last activity: [10 months, 3 weeks ago](https://wordpress.org/support/topic/invalidcharactererror-setattribute-async-bug-in-gues/#post-18547184)
 * Status: resolved