tankianann — 2010-10-06T22:57:51-04:00 — #1
Hi, I am building a mobile version of a website and hoping to achieve that using CSS3 media queries instead of sniffing browsers and redirecting to a mobile version.
I am wondering if there is a good way to resize images dynamically (or load a different image) using CSS, to save mobile bandwidth? i.e. if the width of the device browser is 320px, doesn't make sense to load a 500px wide image right?
Any pointers / resources for this will be much appreciated!
tankianann — 2010-10-07T10:36:20-04:00 — #2
Thanks Paul and Ralph. Its interesting to know that display:none images are not loaded.
Looks like there is still some loopholes in getting the sites easily migrate-able to mobile platforms. Can't expect my clients to code CSS background images!
paulob — 2010-10-07T04:30:39-04:00 — #3
I would do as Ralph says and use background images so that you can link to a different image for the smaller screen.
As a general rule images are only downloaded when they are presented on screen (or off screen id negative positioning is used) and not generally loaded width display:none (which is why pre-loading techniques either place the images off screen or make them 1px high).
You can find a good article here:
ralphm — 2010-10-07T08:02:58-04:00 — #4
Wow, very interesting. Didn't know that, but did wonder about it. Thanks Paul.
ralphm — 2010-10-07T03:15:57-04:00 — #5
If the mobile version is at a different domain, then just use a smaller image in the HTML. But it sounds like you are just offering different styles for the same site when it appears on a mobile device. In that case, I think you can only control background images—that is, link to a different (smaller) image as a background image via CSS. Media queries can't affect the actual HTML content. Even if you set one image to display: none and the alternative image to display, I think the browser still downloads the display: none image (but I'm not certain of that, so we'll have to await more knowledgeable replies .)