This solution uses CSS to prevent background images from loading, and jQuery to prevent images from loading. I am not familiar with any CSS solution that will prevent image loading.
JS Fiddle: http://jsfiddle.net/CoryDanielson/rLKuE/6/
If you know the height and width of the images (or even the ratio) well in advance, you can set the background-image for a fixed-size DIV group. This may be applicable for images and layout images. The following is an example of HTML / CSS.
Background Images
aside { display: none; } @media screen and (min-width: 750px) { aside { display: block; } .catpicDiv { height: 100px; width: 100px; display: inline-block; border: 1px solid red; background-image: url('http://img2.timeinc.net/health/images/slides/poodle-1-400x400.jpg'); background-size: cover; } }
and HTML
<aside> <div class="catpicDiv"></div> <div class="catpicDiv"></div> <div class="catpicDiv"></div> </aside>
Image elements are another story ...
I donโt know any pure CSS solutions to prevent them from loading images. Therefore, I would solve it as follows:
Define IMG tags as follows
<img src="" data-src="url-to-image.jpg" />
Then, somewhere at the beginning of the document you need a similar javascript
1) Function to download all images
function loadAllTheImages() { $("img").each(function(){ $(this).attr('src', $(this).attr('data-src')); }); }
2) A code to determine if the user is on a mobile or PC (slow and fast connection), and then upload images. This code is not bulletproof, there are much more accurate and reasonable tests than this.
$(window).load(function(){ if ( $(window).width() > 750 ) { loadAllTheImages();
3) Like and maybe some kind of code to activate the button to upload images? Why not, I think ...?
$(document).ready(function(){ $('body').prepend("<h1>" + $(window).width().toString() + "</h1>"); $('body').on('click', '#mobileCheck', function(){ loadAllTheImages();
A similar solution, as here, and what I suggested in the comments:
Delay loading images using jQuery