[solved] Js Defer problem

Discussion in 'LiteSpeed Cache Plugin For WordPress' started by Federico, Oct 12, 2017.

  1. Federico

    Federico New Member

    Good morning and compliments for the work you do. However, the js option defer me to problems, when the active button looks and the menu on mobile does not work. How can I fix it? thank you
  2. Jon K

    Jon K Administrator Staff Member

    We are aware of this compatibility issue, it caused by the inline script which directly used jquqery without waiting for document ready (not fully loaded page). We are working on a fix.
  3. Arild

    Arild New Member

    Looking forward to se a fix for this problem. For me js defer also create a problem with the page title bar. Keep on the good work.
  4. Unique_Eric

    Unique_Eric Active Member

    LSCache v1.5 have a function called "Exclude JQuery", which enabled by default should fix the issue.
  5. Zan

    Zan Member

    Hi @Unique_Eric I am using version 1.7 and still running into this issue and I can see that Litespeed cache has moved the query file to the far bottom of the page which means that inline scrips that are relying on Jquery are triggering errors messages. To be exact the error message says: Uncaught ReferenceError: jQuery is not defined at (index):106

    I have tried Exclude Jquery (both on an off - currently on), Exclude URI etc with no success. Maybe it is is broken a gain?

    I would really appreciate your help


  6. hai

    hai Active Member

    When you enable Exclude JQuery, the jquery should be in the top of the page. Can you give a page or a report number so we can check?
  7. Zan

    Zan Member

    Thanks Hai,
    I ideally wouldn't want it at the top of the page either. I have moved it to the bottom of the page but put other scripts that rely on it beneath it. I ideally would want Litespeed cache to just leave it alone exactly where it was at the bottom but the last item. Putting it at the top would slow down the rendering of the page.

    I am having problems posting a link on here
  8. Zan

    Zan Member

    Add the following up to get the url please: home loans compare. co. nz /balance-transfer-credit-cards/
  9. hai

    hai Active Member

    As long as you turn on JS defer, it won't slow down your page loading. Also if you have HTTP/2 push on, it will be faster.

    WP puts JQ before <body> tag, if you move it to bottom, you added a new one manually? In this case, you can disable LSCWP's optimizer to move it by adding attribute `data-no-optimize='1'` to your jq.
  10. Zan

    Zan Member

    Thanks Hai. What do you mean by adding attribute `data-no-optimize='1'` to your jq. You mean open up javascript and add this to the code?
  11. Tishu

    Tishu Well-Known Member

    You need to add that "data-no-optimize='1'" when you are loading the JQ ( in <script src=.... ).
  12. Zan

    Zan Member

    Thank you so much for your help guys adding that to the jQuery script fixed the problem. I love LiteSpeed Cache btw.
    For benefits of others, just to be clear, you can add data-no-optimize='1' to your script tag as shown below to stop LiteSpeed Cache from optimising it and so it won't be moved around. It basically tells LiteSpeed cache that the script has already been optimised and should be left alone is what I gather.
    <script type='text/javascript' data-optimized='1' src='https://www.creditcardscompare.co.nz/wp-includes/js/jquery/jquery.js'>

Share This Page