Why do images on the web load line by line? - css

Why do images on the web load line by line? Why not from top left pixel to bottom right pixel? Is it about browser or css defaults? Is it possible to change that to show pixels at the moment they are loaded or after whole image is loaded?

It has to do with the order they appear in the html document. The positioning in the page, doesn't matter in the loading priority.

You can with Javascript or JQuery, like this:
$("#img").hide();
$('#img').load(function(){
$('#img').show();
});
Basically it shows the image only if the whole image is loaded.

You are talking about how exactly the image itself is loaded/rendered? It's a mix of:
implementation detail in each browser
how the image is formatted (which format, gif/jpeg/png
Can you control it using CSS? No, not really. You might do some effects using CSS animations/transitions, but not pixel by pixel. Not in an efficient manner at least.

It depends on image format, some can load line by line, some are "progressive" and can load in "chunks" (firs a blurry, pixelated image is visible, then it loads some more data and becomes less blurry, and so on), some have to load in full before they can be displayed.

Related

Resizing images via css

If an image is 200px by 200px and you give that image a class in css with the same dimensions, will the browser still resize that image via css?
Ive been looking frequently into reducing page load time and one of the things that comes up is resizing via css slowing down page load time.
If you apply a class to your image with some fixed dimensions, then it will stuck to the defined dimensions.
Unless you define "max/min-width" and "max/min-height" instead of width and height.
The loading time is not about the dimension of the image but more about the size (octets) of the file (here an image). The performance are poorly influenced by the dimension of it.
No, because image will be same size (as downloaded from server). Also, since width/height of class is same as image, image will not be resized. And I don't think that resizing such images has any impact on page load times.
We can resize image propertionally from css but can't reduce load time from css
Full optimization of images can be quite an art to perfect as there are such a wide variety of images you might be dealing with. Here are the most common ways to optimize your images for the web.
Use proper file formats. If you have icons, bullets or any graphics that don't have too many colours use a format such as GIF and save the file with lower amounts of colours. If you have more detailed graphics then use JPG file format to save your images and reduce the quality.
Save your images in the proper dimensions. If you are having to use HTML or CSS to resize your images, stop right there. Save the image in the desired size to reduce the file size.
To resize your images you will have to use some form of program. For basic compression you can use a simple editing program such as GIMP. For more advanced optimization you will have to save specific files in Photoshop, Illustrator or Fireworks.
Source Link
Edit:
Check this link to get more idea about speeding up page loading time

Prevent progressive (line by line) loading of background image

I am looking for a way to have the background-images (CSS) load as if they were appearing once loaded, and not "rolling down". I'd rather have an image appear 300ms late in one flash instead of having it appear like a bad PowerPoint effect.
Any techniques or specific code that could be used (besides caching)?
Thanks,
jsfiddle http://jsfiddle.net/9fFKT/3/
$("#bg").hide();
$('#bg').load(function(){
$('#bg').show();
});
using jquery you can hide until it loads and display it once its loaded
Basically you'd need to either have the elements hidden on initial load, or to have no background set in CSS, add the image via JavaScript, then apply the CSS background with the onload event of each image.
CSS alone cannot do this.
You could load the image as hidden at the top of your page, so when you put it into the DOM later it is a cached copy. Or, you can put a hidden attribute on it, and after a 300ms timer, turn hidden off. The latter will do what you want with more certainty, but it depends on your viewers network speeds.
First, if your image appear in "rolling down" it's Image it's too heavy.
Exist different program or website for reduce your image for web ( without losing quality )
for sample, Yahoo SMUSH.IT! is good for that!
After, I don't know if existing a method for appear background-image after download... maybe in JavaScript...

How can I shrink an image in HTML whilst maintaining its sharpness?

I have an image that I use many times. In several cases I want to shrink its size, but obviously it loses sharpness when I do this in HTML.
Is there a way to fix this? The image is located elsewhere and I can’t save it locally.
Thanks
As dheerosaur states, SVG graphics can be used when you need to have the same image in multiple sizes but don't want to compromise quality.
Another thing to do is use an online service, such as Resize.co. You pass them the URL for your image file, the attributes and they take care of everything else.
You cannot control the way the browser renders images when they are resized. Images will look better when being passed through Photoshop's filters (or those in another tool) upon resize.
There is three way that I know to reduce an image file size in bytes :
Convert the file into a format using lossy compression algorithm such as JPG. Obviously the image will lose sharpness
Convert the file into a format using lossless compression algorithm, like PNG. Only works if the image contains lots of region with flat colors
Resize/resample the image using Photoshop or GIMP. If the new image dimension (width x height) is exactly the same as the displayed image's dimension in HTML, then web users will still see a sharp image
Firefox and Internet Explorer actually do have CSS properties that adjust the way images are rendered when resized via HTML attributes or CSS properties:
Firefox: image-rendering
Internet Explorer: -ms-interpolation-mode
These won’t work in other browsers, and may not work great in all (or any) versions of IE and Firefox.
But it might be worth experimenting with them as a fallback in case resizer.co causes any issues.

Image precaching

at the website I'm working on euroworker.no, I have a ton of CSS rollovers, that only load when rolled over, is there a way to force load these onLoad so that they don't flash when rolled over the first time? It makes the site look broken. I could use a <body onLoad...> but am not sure how to implement it.
Thanks.
Sure, just use image sprites. In short, this means you put both states of an image (default and hover) in one image file. Upon hover, you then shift the background-position of the element in question.

Background image shows through briefly

I have a site that uses a large centered background image, which naturally loads a tad slower than the other elements on the page. For the most part this works okay, but there is also a repeat-x background image that covers the background for large monitors. The only problem is that this smaller file loads first and flashes briefly before the large image loads fully. Is there a way to have the large image load first so it is in place before the repeating background image loads? Thanks!
I don't know whether there is a way to accomplish that but you can use either javascript or jquery to change your dom elements show priority.
There's no way using strictly css to absolutely control the order images load.
The browser will try to download the images in the order they're listed in the css file, so putting your large background iage first will help, but the download time is gonna make it a moot point more than likely.
You could load the larger background via javascript once the rest of the DOM has loaded if it's worth going that far.
I figured out the answer to my own question: Instead of repeating the whole pattern of the upper body, I used only the pattern portion that is where the main content is. This loads quickly and looks natural behind the content while the large image loads. Thanks Aaron for the reply.

Resources