• Home
  • New Entries
  • Popular Entries
  • Submit a Story
  • About

Preloading Images ...

What javascript does is allow you to start loading the images in the HEAD section of your page, which means that with this technique (unless the images are large or great in number) your viewers will have the necessary images in their browser's cache before the script starts to run. This way, an image rollover will be less likely to make the viewers wait for the browser to download the second image, because it is in their browser's cache.

Preloading images is a technique often used in Rollover Effects or other image scripts which work more quickly when the images for them are loaded as soon as possible.

What javascript does is allow you to start loading the images in the HEAD section of your page, which means that with this technique (unless the images are large or great in number) your viewers will have the necessary images in their browser is cache before the script starts to run. This way, an image rollover will be less likely to make the viewers wait for the browser to download the second image, because it is in their browser is cache.

To get this going, you need to have a small section of script in the HEAD section of your page. Here is a sample of a script that preloads a single image:

<SCRIPT language="JavaScript">
<!--
pic1= new Image(100,25);
pic1.src="http://someplace.com/image1.gif";
//-->
</SCRIPT>

The first command defines a new image object, giving it a width of 100 and a height of 25. You would replace these with the width and height of your image. The second defines the url or web address of the image. You would replace this with the url of your image. Not too bad now, is it?

However, there is a chance your viewer will come through with an older browser which doesn support the image object. So, to be on the safe side you may wish to implement a form of Browser Detection or Object Detection to keep from giving the older browsers a javascript error. I will use the shorter one here, which is object detection. For more on object detection, see the tutorial on what it can do.

Here, we want to know if the image object exists, which in javascript is "document.images". So, we just need to check for it with an if condition, and then run the preloading code:

<SCRIPT language="JavaScript">
<!--
if (document.images)
{
  pic1= new Image(100,25);
  pic1.src="http://someplace.com/image1.gif";
}
//-->
</SCRIPT>

There, now you have the code to preload (what a rhyme!). If you want to do this for multiple images, just be sure to assign them a different name-- such as pic2, pic3, and so on. Adjust your width, height, and urls accordingly. You will have two lines for each image. For example, to preload three images, you would use a code like this:

<SCRIPT language="JavaScript">
<!--
if (document.images)
{
  pic1= new Image(100,25);
  pic1.src="http://someplace.com/image1.gif";

  pic2= new Image(240,55);
  pic2.src="http://someplace.com/image2.gif";

  pic3= new Image(88,31);
  pic3.src="http://someplace.com/image3.gif";
}
//-->
</SCRIPT>
source: pageresource

 View Full Story.
Posted at 11:35:14 am | Permalink | Posted in Image  Javascript  Tutorials  

Related Stuff

  • MooV: Using cutting edge Video phones and Software Video Phones - coupling all that with VoIP and empowering the disabled.

  • Moo Telecom: VoIP communications made easy - Ring anyway with the fun and ease of using a normal phone

  • TagR:Mobile Social Network with Real Time Locations Based services, and Ambience Intelligence, VoiP, IM, Skype, Googletalk, Mapping, Flickr, Events, Calendaring, Scheduling, SecondLife Support

  • ClearSMS : ClearSMS is a Web-based application that lets you send bulk SMS messages to your customers, contacts, or just about anyone.

  • Jajah:jah is a VoIP (Voice over IP) provider, founded by Austrians Roman Scharf and Daniel Mattes in 2005[1]. The Jajah headquarters are located in Mountain View, CA, USA, and Luxembourg. Jajah maintains a development centre in Israel.

  • Skype: It’s free to download and free to call other people on Skype. Skype the number one voice over ip software

  • PrivatePhone: a free local phone number with voicemail and messages you can check online or from any phone.

Be the first ... |Add your comment.

Your Comment ...

  Name (required)

  Email (required, hidden)

  Website


Top Stuff

e-messenger

MessengerFX

eBuddy

ILoveIM

AIM Express

Top 20 Ruby CMS


Our Partners

Facebook Applications

Ajax Projects

Web 2.0 Sites

Webloglines

Human Development Handbook

Software Development Company

Ajaxlines

Stock Exchange Chat


About Ajaxlines

Ajaxlines is a project focused on providing its audience with a database of most of Ajax related articles, resources, tutorials and services from around the world.

Its purpose is to showcase the power of Ajax and to act as a portal to the Ajax development community.


Search


Topics

  • .Net (111)
  • Articles (85)
  • Bookmarking (35)
  • Calendar (19)
  • Chat (39)
  • ColdFusion (3)
  • CSS (41)
  • Email (23)
  • Facebook (23)
  • Flash (15)
  • Games (6)
  • Google (28)
  • Html (14)
  • Image (11)
  • International Calls & VOIP (7)
  • Java (36)
  • Javascript (171)
  • JSON (21)
  • Perl (2)
  • PHP (88)
  • Presentation (19)
  • Python (3)
  • Resources (2)
  • RSS (1)
  • Ruby (10)
  • Storage (4)
  • Toolkits (90)
  • Tutorials (199)
  • UI (12)
  • Utilities (167)
  • Web2.0 (13)
  • XmlHttpRequest (20)
  • YUI (4)

© 2006 www.ajaxlines.com. All Rights Reserved. Powered by IRange