2

I need to get my java script files to load after the page has loaded, i read this blog

http://www.feedthebot.com/pagespeed/defer-loading-javascript.html

and it says to use this code

<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>

at the bottom of our html file before the end of the body tags. What file do i need to add this to in magento to get the file to load after all the CSS and images? as it is slowign down our website loading them all firs?

or if you know any other ways of deferring the java files could you let me know

thank you in advance

2

you can add it in footer.phtml file from app/design/default/your_theme/template/page/html/footer.phtml

Or you can add it in app/design/default/your_theme/template/page/1column.phtml (2columns-left.phtml ... etc) all files from the "page" folder with "column" in name :). Here you will find the closing body tag.

Depending on your theme, that script might not work, if you have prototype calls from your files that are not under dom loaded event, will generate errors..

protected by Fabian Schmengler Aug 11 '15 at 14:08

Thank you for your interest in this question. Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).

Would you like to answer one of these unanswered questions instead?

Not the answer you're looking for? Browse other questions tagged or ask your own question.