Skip to content

Instantly share code, notes, and snippets.

@oreshinya
Created November 2, 2012 15:31
Show Gist options
  • Select an option

  • Save oreshinya/4002019 to your computer and use it in GitHub Desktop.

Select an option

Save oreshinya/4002019 to your computer and use it in GitHub Desktop.
create js for preload images
IMAGES_PATH = "images/"
OUTPUT_PATH = "javascripts/"
images = Dir.glob(IMAGES_PATH + "**/*.jpg").join("','")
js_str = <<-JS_STR
(function() {
var image_preloader = {
images: ['#{images}'],
done: function() {
for (var i = 0; i < this.images.length; i += 1) {
(new Image()).src = this.images[i];
}
}
};
image_preloader.done();
})();
JS_STR
open(OUTPUT_PATH + 'preload_images.js', 'w'){|f| f.write js_str}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment