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

|improve this answer|||||

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