2012-07-31 8:15, Barry Margolin wrote:
> In article <
5658cd9d-20f4-4fd1...@googlegroups.com>,
> Jason C <
jwca...@gmail.com> wrote:
>
>> Let's say that I have this:
>>
>> <div style="display: none">
>> <img src="whatever.jpg" width="75" height="75" border="0">
>> </div>
>>
>> Is the image still going to load in the background, and just not show on the
>> page? Or does it not load at all, and take no bandwidth?
[...]
> Why don't you check the log on your server to see which images have been
> requested?
Not a very practical idea for several reasons, including the possibility
than an author may have absolutely no access to server logs. More
practically, hit F12 on any normal modern browser and use its debugging
and inspection tools.
For example, on Chrome, after hitting F12, select the "Network" tab and
open your test document. I didn't even need a real image file on a
server, I just used an <img> tag with an invented src attribute and saw
Chrome sending a GET request to the server identified in it.
So yes, although this is not specified in the specifications and
browsers could conceivably behave otherwise, browsers do fetch image
resources specified in src attributes even though the <img> element is
affected by display: none. This keeps browsers a little simpler, and it
helps user experience when an <img> element is switched to displayable
via CSS or via JavaScript.
Thus, to deal with the given situation,
>> For my purpose, I have a page with about 2,000 images, and I'm using
>> display: none to hide all but the first 50; then, as the user
>> scrolls down, I'm changing display: to "block" based on scrollTop.
>> What I'm wanting to ensure is that, even though the pictures are
>> hidden, they're not still loading in the background until they're
>> needed.
... the page should be constructed e.g. so that its <img> tags have fake
src attributes, or no src attributes at all, and these attributes are
changed or added when additional images are to be shown. You can't do
such things in CSS, you need some client-side scripting, or you need to
divide the material to different pages.
On the other hand, the approach results in suboptimal user experience.
There would be a delay when moving from one set of images to another. A
better approach could be (if you expect the image sets to be viewed
sequentially) to have the next set of 50 images downloaded
asynchronically on the background. But this takes us rather far from CSS.
--
Yucca,
http://www.cs.tut.fi/~jkorpela/