Defer parsing Javascript in HTML version


  • Member
    roberthofstede
    September 22, 2018 at 6:30 pm #33223

    Hi,

    First of all I really have to tell you that I like the HTML version Auqa theme. Everything works fine, however there is one thing that I’m struggling with and I hope you can help me a little bit with this.

    I do have some problems with defer parsing javascript. Now most people use the wordpress theme and I did find some information about defer parsing javascript on your website, but most if not all are related to the wordpress version. I use the HTML version so I cannot use any wordpress plugins for defer parsing javascript.

    So I did use the code below to defer the JS files:

    <script type=”text/javascript”>
    function downloadJSAtOnload() {
    var element = document.createElement(“script”);
    element.src = “defer.js”;
    document.body.appendChild(element);
    }
    if (window.addEventListener)
    window.addEventListener(“load”, downloadJSAtOnload, false);
    else if (window.attachEvent)
    window.attachEvent(“onload”, downloadJSAtOnload);
    else window.onload = downloadJSAtOnload;
    </script>

    This is a pretty standard code that I found on several (authorative) websites. This code needs to be placed just before </body> and only excutes javascript after the page has been build.

    However when I apply this code for all the files, javascript will not execute at all.

    Now there are some JS files that are necessary to build a page. I think that I can find some of the files/code that is necessary to build the page, however whatever I do I do not get it to work properly.

    The code however must be doing something right as Google PageSpeed Insights does not see javascript as a problem anymore after applying the code.

    Now is my question: Do you have some information of how to defer parse javascript correctly for this particular HTML theme? Maybe not with the code as shown about other methods like using async, which also caused a problem when I implemented it is also fine.

    Thanks for in advance for reading and replying to my topic.

    Kindest regards, Robert Hofstede

    Sorry, this forum is for verified users only. Please Login or Register to continue

Comments are closed.