/    Sign up×
Community /Pin to ProfileBookmark

Using Javascript to delay the Loading of Images

We are trying to improve the usability of our website, and its performance rating, by delaying the insertion of elements in the DOM of our homepage until the rest of the page has loaded.

For example, if our homepage contains the html:

<tr>
<td width=37 height=1> <img src=”http://www.consumer.philips.com/repositories/HomePage/en_GB/CE/b2c_bullet_v1/images/spacer.gif” width=37 height=1></td>
</tr>

I have found that if we rewrite it like this:

<tr>
<script language=”JavaScript”>document.write(‘<td width=37 height=1> <img src=”http://www.consumer.philips.com/repositories/HomePage/en_GB/CE/b2c_bullet_v1/images/spacer.gif” width=37 height=1></td>’)</script>
</tr>

…The image is not downloaded until the rest of the page has been loaded, and the download time of the image is not included in the performance measurement of the page.

How can we make it so that a larger, multi-line slab of html is delayed in its insertion into the DOM until the rest of the page has been loaded?

Any ideas welcome

to post a comment
JavaScript

2 Comments(s)

Copy linkTweet thisAlerts:
@CharlesSep 30.2003 — [i]Originally posted by sneakybeaky [/i]

[B]Any ideas welcome [/B][/QUOTE]
[i]Leviticus XIX:35, NRSV[/i]

[b]You shall not cheat in measuring length, weight, or quantity.[/b][/quote]
[i]Deuteronomy XXV:15-16, NRSV[/i]

[b]You shall have only a full and honest weight; you shall have only a full and honest measure, so that your days may be long in the land that the LORD your God is giving you. For all who do such things, all who act dishonestly, are abhorrent to the LORD your God. [/b][/quote]
[i]Proverbs XX:10, NRSV[/i]

[b]Diverse weights and diverse measures are both alike an abomination to the LORD. [/b][/quote]
[i]Micah 6:11, NRSV[/i]

[b]Can I tolerate wicked scales and a bag of dishonest weights? [/b][/quote]
[font=georgia]And besides, what about the 13% of users who do not use JavaScript?[/font]
Copy linkTweet thisAlerts:
@sneakybeakyauthorSep 30.2003 — Useful points and very ably and appropriately put.

But, I'm still set on my course to use Javascript.

If I can encapsulate a slab of html in javascript, It makes it easier for the page to be written so that it still looks good to those without javascript enabled.
×

Success!

Help @sneakybeaky spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.1,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,
)...