Post by dodokids » Thu Oct 31, 2013 5:24 pm

We add the following code right before closing body tag in the footer.tpl :

Code: Select all

<script defer="defer" type="text/javascript">
    window.onload=function(){
        var mycode;
        mycode=document.createElement("script");
        mycode.type="text/javascript";
        mycode.src="http://www.example.com/path/yourjavascriptfile.js";
        document.getElementsByTagName("head")[0].appendChild(mycode);
    }
</script>
But we still receive the mmessage:
"340.8KiB of JavaScript is parsed during initial page load. Defer parsing JavaScript to reduce blocking of page rendering."

Then we try with :

Code: Select all

<script type="text/javascript">

// Add a script element as a child of the body
function downloadJSAtOnload() {
var element = document.createElement("script");
element.src = "deferredfunctions.js";
document.body.appendChild(element);
}

// Check for browser support of event handling capability
if (window.addEventListener)
window.addEventListener("load", downloadJSAtOnload, false);
else if (window.attachEvent)
window.attachEvent("onload", downloadJSAtOnload);
else window.onload = downloadJSAtOnload;

</script>
But still the same message.
Can anyone tell how to solve this?

New member

Posts

Joined
Mon Jul 30, 2012 6:50 pm

Post by dmsims » Thu Oct 31, 2013 11:15 pm

<script src="demo_defer.js" defer></script>

Active Member

Posts

Joined
Sat Apr 13, 2013 6:05 pm

Post by dodokids » Mon Nov 04, 2013 7:37 pm

dmsims wrote:<script src="demo_defer.js" defer></script>
Where to add this line?

New member

Posts

Joined
Mon Jul 30, 2012 6:50 pm

Post by bunnybooboo » Wed Nov 27, 2013 8:45 pm

I would also love to know how to defer the parsing of javascript in opencart. Did you have any luck with this in the end?

Maybe the previous poster was referring to this? http://www.w3schools.com/tags/att_script_defer.asp

I know we all learn stuff like this as we go along pretty much so I am making an assumption that the attribute 'defer' should be used at each instance of javascript needing to be deferred? At this point I have no idea where to look but working my way through it.

Newbie

Posts

Joined
Thu Aug 22, 2013 3:33 pm
Who is online

Users browsing this forum: No registered users and 51 guests