Forum Moderators: open
<img src="b.gif">
<img src="c.gif">
<img src="d.gif">
<img src="e.gif">
<img src="a.gif">
but imgs of a.gif seems still load after b/c/d/e
When the browser renders a page, it also builds a list of other elements it needs to fetch, such as stylesheets and images. The order the elements are fetched in, is entirely browser dependent and probably without any guarantees on the order. Natural choices would be a FIFO (first in, first out) or a LIFO (last in, first out), but it could also be just random. Most of the browsers are also multi-threaded, so they actually do more things at a time, so they might have several images in the download pipeline, added to the randomness of the downloads.
So you can't rely on any particular order.
René
i'm not making it must be the first load, but as ahead as possible
<link rel="stylesheet" href="a.gif" />
hope this will cheat the browser to preload a.gif without side effect
what i want to do is preload the imgs of the post of thread(e.g.: the :) icon and images of ubbcode )
before any other imgs of html(bg of TABLE/TD, src of IMG, src of INPUT[type=image]
For some browsers, it helps to declare the dimensions in your preload script -- newImage(width,height)
If the visitor is likely to visit another page first, you can try including a preload for the troubelsome image there -- so it's already cached when it comes time for the main show. Nevertheless, the rendering order is not ultimately under your control.
but when 20 un-important images follow by 1 important, browsers often start from the first imgs, it don't know which img should load first.
what i NEED is just make individual browser load important image first then un-important
a workable methos may be:
<img src="important.gif" style="width:1x;height:1px" />
<img src="un-important1.gif" />
<img src="un-important2.gif" />
......
<img src="un-important20.gif" />
-> <img src="important.gif" />
just wonder if there's any perfect, or more suitable method
well, seems i have explained too much :)
thank u guys who reply this post
Then call a function onLoad that would switch out the other images on the page from the blank image to what they 'really' want to display.
My guess is that this would slow down the page a bit -- as well as requiring javascript to see the images!
Maybe the best way to ensure that certain images are loaded first is to have them loaded by an previous page, so they are in the browser cache, *and* make sure they have the proper Last-Modified and Expires headers sent, so they are in fact cached efficiently.
René.
seindal:
both "lowsrc" and preload in previous page is easy to maintain for static page, but not for dynamic
suppose you're writing a forum(bbs), there is thread_list.php and thread.php, it's not possible to pre-load images in thread_list.php and user may not click into one of that thread.
un-important images-->images of user interface
important images-->images post by user
maybe... i should reload those un-important images of thread.php in thread_list.php
then when user click into thread.php, because all un-important images is already loaded, now start download important images
but... when using window.open(), some un-important images seem being reload again even it's loaded in cache. i'm puzzled...
but... when using window.open(), some un-important images seem being reload again even it's loaded in cache. i'm puzzled...
Check your expiry headers. Maybe things are being cached as efficiently as you think. There is a very good tool at [ircache.net...] "Cachability Checker". It'll run a few checks and tell you whether your files cache well.
René.
Far from ideal but it might preloade "important.gif" before your actual containing HTML page is called.
"DUCK"
to all:
as a mordern browser, it's so smart to load what it think important first itself.
e.g.: display:none imgs will not be load first, new Image().src=.... will be load after all other imgs in HTML tags
anyone study the this "smart" behavior of a specified browser?
to piskie: can u share me your WebSpeed-sim?
to seindal: i did override the header to make the page cachable, only some gif/jpg reload in newly open window, some not, it's random
If things are set up correctly you will see the graphics elements being fetched on first request, but they shouldn't even be ask for on subsequest requests. If the browser still asks for them, getting either a 200 or a 304 response, your expiry headers on images are not good enough.
You need an "Expire: xxx" header in the HTTP response for each image sent. The expire information on you main page is of no use for the images.
This is what you server should send for a cachable image:
Cache-Control: max-age=604800
Expires: Sun, 15 Dec 2002 09:42:08 GMT
Last-Modified: Mon, 18 Feb 2002 13:45:51 GMT
You can check it at:
[searchengineworld.com...]
Just enter the url to your image and you will see all the HTTP headers sent to the browser.
To set the expire headers on images you might need access to the server configuration. If it is Apache, you need something like:
# Expire in one week
ExpiresActive On
ExpiresByType image/gif A604800
ExpiresByType image/jpeg A604800
ExpiresByType image/png A604800
ExpiresByType image/x-icon A604800
ExpiresByType application/x-javascript A604800
Caching is a bit tricky, but it can speed things up quite a bit and also take some workload of the server, if done correctly.
I hope all this helps you a bit.
René
It is my guess that the browser will attempt to fetch images in the HTML source first, then begin to evaluate script elements. This is because visible Image size must be determined for the browser to even begin to render a page (eg: img tags in a table).
That said, I have seen another "trick" to cause images to be loaded early: Use img tags right after (or near) your "BODY" tag and set the image width and height to 1. If the images are small, they will load fast, and the browser will have a copy in its cache. Because the images are small, they will be almost invisible. You can spread the img tags around (like after your main logos load) within the HTML if there are many, so that they will not prevent your page from becoming visible for very long.
The most important point is to consider the concurrency capabilities of a browser, and design your page so that performance isn't compromised by "flash." You would still use the pre-fetch javascript, and by the time it runs, the images will be ready to go, in the browser's cache. --Chris
to spinnercee: hm.... u pointed out the key point why my script
<script>
var img = new Image(); img.src = 'a.gif';
</script>
won't do as i expect
cos it's invisible.
the only way to make it "visible" is make img tags in <body>..</body>
======
again:
how about <link rel=stylesheet href=important.gif />?
css should be load at the very first.
any effect/side effect?
will it waste client cpu to parse/skip content of the gif?
Speaking of performance, using a .gif, instead of a .jpg image can help page load time. While a .gif is typically larger bytewise than a .jpg image, even when using only 256 colors, it can be rendered (displayed) faster by the browser because it does not have to be decompressed (as much) like a .jpg does. Especially if you're using "onMouseOver" stuff, the images will pop-in and -out faster, if you use .gif -- the effect is noticeable and persistent even when the images are in the browser cache. The .jpg [and most good] decompression algos are CPU-intense, compared to simply "mapping-out" a bitmapped image -- there's always a trade-off -- where the .gif images are color-limited, and will take longer on initial load.
Then I did something close to what spinnercee spoke on. Next to the images that get replaced onMouseOver, I added <img src="image1.gif" border="0" height="0" width="0">. It makes it easier to maintain by having the non visibile image next to the visiblie image. The images are then cached.
Concerning the number of connections the browser has open to receive content, Mozilla has an option called 'Enable Pipelining'. If I understand it correctly, all Get requests are sent at one time. As it was once explained, there are limitations to the way a browser requests from a server. Generally, the browser worked like this:
get... receive
get next...receive next
If it were four it would be:
get
get
get
get
receive
get
receive
receive
receive
receive
with pipelining enabled all gets are sent and the queue on the webserver sends them. That being the case, the 0 width-height images would not affect the content load?
This is a great topic!
Actually it reverses the problem. Is it possible to load some images after others, but the result can be almost the same.
First the unimportant images have their SRC set to something small, like a 1x1 blank gif. Make sure it caches well, because several images will probably use that image. Give each IMG tag with the blank image a NAME or an ID (depending on your doctype declaration). Then insert some javascript that will change the image displayed after some time, using window.setTimeout(). The timeout can probably be rather low, like half a second, just enough for the browser to schedule fetching the other images.
There are some problems with this approach. It is rather cumbersome for many images and it degrades horribly if the user has disabled javascript.
It works well for my slideshow, since it is not an essential part of the page. It is basically an ad for other parts of the site. If there is no javascript, people just get stuck with the first image. No problem.
René.