| Recommend this page to a friend! |
| Trackbacks (0) | ||||||
| >> Next: Load Page Content Fas... |
<script type="text/javascript" src="contentLoader.js"></script>
Do we want to see debug messages in the browser console or alert window?
<script type="text/javascript"><!--
var cl = new ML.content.contentLoader();
cl.debug = true;
cl.delayedContent = '<div style="text-align: center">' +
'<img src="http://ajaxload.info/images/indicator.gif"' +
' width="32" height="32"></div>';
// --></script>
You need to convert this HTML to tags with JavaScript code like this:
<a href="http://twitter.com/share" class="twitter-share-button"
data-count="horizontal" data-via="jsclasses">
<img src="http://ajaxload.info/images/indicator.gif"
width="32" height="32" alt="ReTweet" align="middle" border="0">
ReTweet</a>
<script type="text/javascript"
src="http://platform.twitter.com/widgets.js"></script>
<script type="text/javascript"><!--
cl.addContent({
content: '<a href="http://twitter.com/share"' +
' class="twitter-share-button" data-count="horizontal"' +
' data-via="jsclasses">' +
'<img ' +
' src="http://ajaxload.info/images/indicator.gif"' +
' width="32" height="32" alt="ReTweet" align="middle"' +
' border="0">' +
'ReTweet</a>' +
'<' + 'script type="text/javascript"' +
' src="http://platform.twitter.com/widgets.js"></' +
'script>',
inline: true
});
// --></script>
Here the content string was broken into multiple lines to make this article look better, but usually you do not need to do that.
The only thing you need to do is to break the HTML tags <script> and </script> into '<' + 'script>' and '</' + 'script>', so browsers do not confuse those tags in the string with the beginning or the end of JavaScript code sections.
You should repeat this procedure of replacing the original tags of slow content by delayed content JavaScript code tags until all slow content tags are replaced.
The last step is to define the position in the page where the slow content should start loading. Usually it is the last thing in the page but it can be places before that position if you want slow content to start loading sooner.
<script type="text/javascript"><!--
cl.loadContent();
// --></script>
This last call to the content loader object will insert in the page the previously defined slow content inside hidden <div> tags. The object will wait whatever time it takes the browser to load the remote content.
Once the slow content loads, the object moves the DOM nodes of the just loaded slow content to the original positions. The the slow content starts appearing where it should, but without delaying the load the rest of the page.
The slow content loading procedure works fine in all browsers but for some reason under Internet Explorer and Opera the content may end up being loaded outside the hidden <div> tags added to the page by the loadContent function.
This is somewhat unexpected. So far no workaround was found to solve this problem. Therefore, in the current version of the object, when the browser is Internet Explorer or Opera, the object does not delay the loading of the slow content. Instead, it just inserts the content exactly where it was originally intended to appear. For these browsers the content will still slow down the load of the page as before.
If you have any ideas of how to avoid this problem of Internet Explorer and Opera, please post a comment to this article so you can help improving the content loader object browser support.
Comments:
1. Fast loading Ad JS - Eion Robb (2010-11-23 08:02)
Fast loading Ad JS... - 1 reply
Read the whole comment and replies
| >> Next: Load Page Content Fas... |
| Trackbacks (0) | ||||||