473,398 Members | 2,335 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,398 software developers and data experts.

Making an image download before the rest of the page does?

Hi,

Is there any JavaScript that can force the download of an image or a list of
images before the HTML, or any other images are downloaded? This is
necessary so I can force the background image to download before anything
else does.

TIA,

Keiron
Jul 20 '05 #1
2 6761
I do agree with Lasse Reichstein Nielsen that if the page is useless without
the background then redesign it.

On the other hand, why don't you look at the problem from the other
way. How can I hide the contents until the picture(s) are loaded ?

Use the following statement to hide everything inside a DIV:
document.getElementById("YourDivID").style.display = "none";

Use the following statement to show everything inside a DIV:
document.getElementById("YourDivID").style.display = "";
"Lasse Reichstein Nielsen" <lr*@hotpop.com> wrote in message
news:8y**********@hotpop.com...
"Keiron Waites" <webmaster@-NOSPAM-sharemonkey.com> writes:
Is there any JavaScript that can force the download of an image or a list of images before the HTML, or any other images are downloaded?


Not before all the HTML (the script has to come from somewhere), but
you can start downloading simultaneously (up to the browsers limit of
simultaneous connections).

<script type="text/javascript">

function preloadImg(src) {
var dummy = new Image();
dummy.src=src;
}
preloadImg("background.png");
preloadImg("img1.png");
preloadImg("img2.png");
preloadImg("img3.png");

</script>
This is necessary so I can force the background image to download
before anything else does.


This will not pause the HTML while you load the background.

If your page is unusable unless the background image is loaded,
then you should redesing your page.

/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
Art D'HTML: <URL:http://www.infimum.dk/HTML/randomArtSplit.html>
'Faith without judgement merely degrades the spirit divine.'

Jul 20 '05 #2
If you are willing to use a preload page, you can load all of the
images before your page starts. Dynamic Drive at www.dynamicdrive.com
has ready-made preload pages. You can use most of them for free
provided you leave the Dynamic Drive credits intact in comments in the
script. They are easy to use. You have to set up two 1 x 1 px solid
color gifs for the colors of the status bar. You can position the
loading status bar as desired. You put in the URL of your main page to
which you automatically transfer as soon as preloading is completed.
You must fill in an array of URLs for your images. If your page takes
a bit of time to load you can include some text on the preload page to
keep the viewer busy while preloading. Also you can tell a viewer to
reload and/or turn on JS if there is no motion of the preload bar. A
preload page may not be right for every application, but it is a nice
trick to have at hand for many pages that otherwise produce problems.
Jul 20 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

14
by: Jeff Gillingham | last post by:
I'm using a stylesheet to place a small 'background image' in the upper left corner of several pages. Is there a simple way of making that image a clickable link? Thanks.
49
by: Lauren Wilson | last post by:
Hi folks, Just wondered if, for the sake of clarity, it is permissible to post small image files of an error box along with a text message about a problem with Access?
4
by: David W. Simmonds | last post by:
Is there a way I can have a button on a ASP.NET form that when clicked will allow the user to save the image to a file on the client side? I know that the user can simply rclick the image and...
4
by: moondaddy | last post by:
Using vb.net I need to download image files to the client browser where they can save to disk. Below is some sample code I'm using. when I run this the File Download window in the browser says: ...
2
by: Irfan Akram | last post by:
Hi Guys, I asked this question yesterday, but have not yet received a suitable answer. I hope you guys can help me out. I want to load an image on to a web-page. The image is alreday stored in...
1
by: Miguel Dias Moura | last post by:
Hello, I have a GridView in my page which is created in runtime. It works fine. My page has 2 Asp Buttons: - The HIDE button makes GridView.Visible = False; - The SHOW button makes...
6
by: RoseW | last post by:
This is a collection of images with its own style sheet to create the hover over the thumbnail and the larger image appears. http://www4.webng.com/chesleyhs/images/planting/Planting.html Narrow...
8
by: yawnmoth | last post by:
A webpage can include any number of images, cascading stylesheets, frame's, etc. How might I go about making it so a particular image loads before any of these others? Ideally, the image would...
2
by: David Griffiths | last post by:
Hi all I posted this on vb.contols but the group does not seem to be as active as this one. Using VB2005 I have a Web page that I am trying to load images as thumbnails. At present I am...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.