views:

146

answers:

4

I have a page with several galleries including accordions and sliders. The problem is that the page takes forever to load. Is there a way of wrapping an image in a bit of code or applying a class to it to force it to load only after everything else is loaded?

A: 

There is no way (that I know of) to do what you're asking.

To make a page with numerous image load faster, check out Javascript Preloading.

EDIT: turns out I was answering a different question, so please disregard this response.

ABach
@ABach, you know Stack Overflow allows you to add comments right? Why try answering a question if you're not sure?
pixeltocode
@pixeltocode - I believe I did offer an answer in the form of that link. The fact that I expressed uncertainty doesn't preclude the answer I provided.
ABach
@ABach, the question was 'is there a way to force an image to load AFTER everything else is loaded' and not 'how to make a page with numerous images load faster'. i agree you had an answer but not for this question.
pixeltocode
That's fair - I made an incorrect assumption that by speaking about issue #1, he was implying a need to solve issue #2. Thanks for correcting me. :)
ABach
+4  A: 

Sure you can. Replace your img src attributes with a "#", and add a custom attribute, something like this:

<img src="#" delayedsrc="http://mydomain.com/myimage.png"/ >

Then, add a javascript line when your page loads that does something like this (untested, but you get the idea):

$('img').each(function(){
  $(this).attr('src', $(this).attr('delayedsrc'));
});
jvenema
Cunning, that may just be what I need.
DCD
You may need to make that a blank.gif instead of # to keep IE happy, but it should work.
jvenema
I Like it, nice approach :)
Justin
+1  A: 

Keep only one image into the HTML so that viewer has something to start with, then inject the rest using jQuery with $(document).ready(function(){//load rest of the images}); You can also use event loaders and AJAX or "load as you go", just build a simple call back function if it's auto-rotating gallery or load on click.

Tumharyyaaden
+1  A: 

If you're using jQuery (and I assume you are as this is tagged as such) take a look at the Lazy Load Plugin for jQuery. It delays the loading of images that are outside the viewport until the user scrolls to them.

David Lantner
Will it display images that are technically inside the viewport only obscured?
DCD
Test it and find out :-) Its a very easy to use plugin.
Erik