Skip to content

Instantly share code, notes, and snippets.

@qawemlilo
Created February 14, 2011 07:39
Show Gist options
  • Save qawemlilo/825594 to your computer and use it in GitHub Desktop.
Save qawemlilo/825594 to your computer and use it in GitHub Desktop.
Load optimisation
/*
Author: Qawelesizwe Mlilo
Email: qawemlilo@gmail.com
Notes: This script is for optimising loading speed for pages with many images.
*/
// Mootools
window.addEvent('domready', function () {
$$("img").each(function (image) {
var currentImage = image, og_src = currentImage.src ;
if (!currentImage.complete) currentImage.src = "images/place_holder.gif";
window.addEvent('load', function() {
currentImage.src = og_src;
});
});
});
// JQuery
$(function () {
$("img").each(function () {
var currentImage = this, og_src = currentImage.src ;
if (!currentImage.complete) currentImage.src = "place_holder.gif";
$(window).load(function () {
currentImage.src = og_src;
});
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment