Title: Lazyloading breaks Javascript
Last modified: December 8, 2019

---

# Lazyloading breaks Javascript

 *  Resolved [dK](https://wordpress.org/support/users/dkristanda/)
 * (@dkristanda)
 * [6 years, 6 months ago](https://wordpress.org/support/topic/bug-lazyloading-breaks-javascript/)
 * Hi,
 * This is a very confirmed bug! Cause me a lot of headaches.. but at least I found
   the exact root cause.
 * Using Version 0.11.0, when the lazy load is enabled (General Setting=> User Experience
   => Lazy Loading) any image tag that is inside a javascript variable would be 
   broken/not valid. Cause: the regex string-replacement, perform by LazyLoad_Plugin.
   php put class=”lazy” and placeholder src=”data: …” into the img tag without escaping
   the quote.
 * For example, put the following simple script to the page:
 *     ```
       <script>
       var mydef ={"myimage":"<img src=\"https:\/\/www.example.com/myimage.jpg\" alt=\"image desc\">"}
       </script>
       ```
   
 * If the lazyload is active, the javascript will breaks into:
 *     ```
       <script>
       var mydef ={"myimage":"<img class="lazy" src="data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%201%201'%3E%3C/svg%3E" data-src=\"https:\/\/www.example.com/myimage.jpg\" alt=\"image desc\">"}
       </script>
       ```
   
 * The search and replace should be done in two separate ways diferrentiating javascript
   block and html block.
 * Hope this can be rectified soon, in the meantime, lazy loading is off
    Thanks
   Regards, dk

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

 *  Moderator [Jan Dembowski](https://wordpress.org/support/users/jdembowski/)
 * (@jdembowski)
 * Forum Moderator and Brute Squad
 * [6 years, 6 months ago](https://wordpress.org/support/topic/bug-lazyloading-breaks-javascript/#post-12216826)
 * Side note: could you please leave out `[Bug]` in the topic titles? I removed 
   that. Wrapping something in the title `[like so]` doesn’t do anything and the
   forums already do that for `[ Plugin or theme name ]`.
 *  Thread Starter [dK](https://wordpress.org/support/users/dkristanda/)
 * (@dkristanda)
 * [6 years, 6 months ago](https://wordpress.org/support/topic/bug-lazyloading-breaks-javascript/#post-12216858)
 * I see, thanks for letting me know!
    I think it is a very useful denominator for
   support personnel to differentiate with a general question. Can I use the word
   without square bracket? i.e: “Bug: topic” Thanks
 *  Thread Starter [dK](https://wordpress.org/support/users/dkristanda/)
 * (@dkristanda)
 * [6 years, 6 months ago](https://wordpress.org/support/topic/bug-lazyloading-breaks-javascript/#post-12216869)
 * Hi W3TC team,
 * Similar bug also happen in Cdn_Plugin.php when there is a set of source image
   srcset inside a javascript parameter. The culprint is function _srcset_replace_callback()
 * It changes the correct javascript code of:
 *     ```
       <script>
       var myimage = "<img srcset='image2x.jpg 2013w, image1x.jpg 1006w' src='image.jpg'>"
       </script>
       ```
   
 * to
 *     ```
       <script>
       var myimage = "<img srcset="image2x.jpg 2013w, image1x.jpg 1006w" src='image.jpg'>"
       </script>
       ```
   
 * (Note the unescaped quotes)
    Neeed to distinguish html block with javascript 
   block
 * Thanks
 * p.s: in my case all the above is relevant as Elegant Themes is using lots of 
   responsive design process using javascript. Also any site that use ajax that 
   deal with images could be affected.
 *  Plugin Contributor [Marko Vasiljevic](https://wordpress.org/support/users/vmarko/)
 * (@vmarko)
 * [6 years, 6 months ago](https://wordpress.org/support/topic/bug-lazyloading-breaks-javascript/#post-12219467)
 * Hello [@dkristanda](https://wordpress.org/support/users/dkristanda/)
 * Thank you for bringing this to our attention.
    We are checking this and will 
   reply as soon as we inspect this! Thank you!
 *  Plugin Contributor [Marko Vasiljevic](https://wordpress.org/support/users/vmarko/)
 * (@vmarko)
 * [6 years, 6 months ago](https://wordpress.org/support/topic/bug-lazyloading-breaks-javascript/#post-12220053)
 * Hello [@dkristanda](https://wordpress.org/support/users/dkristanda/)
 * Once again thank you for bringing this to our attention. This is now confirmed
   and I’ve open an issue on your behalf in our [GitHub](https://github.com/W3EDGE/w3-total-cache/issues/91)
   public repository. Please make sure to follow the progress of the issue on a 
   regular basis.
    Once again thank you for bringing this to our attention.
 *  Thread Starter [dK](https://wordpress.org/support/users/dkristanda/)
 * (@dkristanda)
 * [6 years, 6 months ago](https://wordpress.org/support/topic/bug-lazyloading-breaks-javascript/#post-12225741)
 * You’re welcome. Just tiny contribution from my part who benefiting from this 
   plugin that can be used for free…
 * I hope you don’t mind if I lodged such finding in this support forum as imho,
   it might help other users more than just directly go to Github.
 * Because you are so responsive, it also gives a good message that this plugin 
   is being looked after very well.
 * Merry Christmas
    Cheers, dk
 *  Plugin Contributor [Marko Vasiljevic](https://wordpress.org/support/users/vmarko/)
 * (@vmarko)
 * [6 years, 6 months ago](https://wordpress.org/support/topic/bug-lazyloading-breaks-javascript/#post-12226598)
 * Hello [@dkristanda](https://wordpress.org/support/users/dkristanda/)
 * Absolutely, this is what this public forum is for. And thank you one more time
   for posting issues and bringing them to our attention!
    Thanks!
 *  Plugin Contributor [Marko Vasiljevic](https://wordpress.org/support/users/vmarko/)
 * (@vmarko)
 * [6 years, 4 months ago](https://wordpress.org/support/topic/bug-lazyloading-breaks-javascript/#post-12407067)
 * Hello [@dkristanda](https://wordpress.org/support/users/dkristanda/)
 * Sorry for the late reply!
    This issue was fixed in 0.12.0 Release. Also, there
   is a new 0.13.0 release with more fixes. Thank you for your patience!

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

The topic ‘Lazyloading breaks Javascript’ is closed to new replies.

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

## Tags

 * [javascript](https://wordpress.org/support/topic-tag/javascript/)

 * 8 replies
 * 3 participants
 * Last reply from: [Marko Vasiljevic](https://wordpress.org/support/users/vmarko/)
 * Last activity: [6 years, 4 months ago](https://wordpress.org/support/topic/bug-lazyloading-breaks-javascript/#post-12407067)
 * Status: resolved