Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Do all CSS background images get loaded even if the CSS isn't applied? [duplicate]

Tags:

css

I'm concerned about load times on home page of our site.

My home page uses a default stylesheet with ALL the styles for the whole site. I have background image references for elements on other pages (i.e. not used on the homepage). Do these background-image graphics get loaded anyways when a user visits the homepage of the site?

Or are the only css background image that get loaded are the ones that are directly used on that page?

like image 893
Mo Boho Avatar asked Jan 20 '10 19:01

Mo Boho


People also ask

Why does my CSS background image not showing up?

Make sure the image path is set correctly in the background-image url. Once you have made sure that your CSS file is linked correctly, also check that the image itself is set correctly. Again, you will want to open your code inspector in the browser to check.

How do I stop a background image from repeating CSS?

To make a background image not repeat in HTML, specify no-repeat in the background-repeat property or the background shorthand property. The background image is set to 'no-repeat' using the 'background-repeat' property.

What defines if a background image will be repeated?

If a background-image property is specified, the background-repeat property in CSS defines if (and how) it will repeat. Here's an example: html { background-image: url(logo.png); background-repeat: repeat-x; }


3 Answers

One way to find out: try a debugging proxy.

The answers may differ for different browsers.

like image 66
Michael Brewer-Davis Avatar answered Oct 27 '22 22:10

Michael Brewer-Davis


The images won't load unless they are actually used on the page; as far as all the styles being loaded on the home page goes -- this is actually a reasonably good thing. Once that single CSS file is in the viewer's cache, its there and doesn't have to be downloaded for subsequent pages.

Someone else's post just reminded me I'm basing my info off of firebug; browsers other then FF may very well download those unused BG images, but I really doubt it.

like image 44
Erik Avatar answered Oct 27 '22 22:10

Erik


Building on Erik's answer, you could use tools like Google's Page Speed addon for Firefox (which I believe is built on top of firebug) and see what is actually slowing down your website when loading.

You can find more info about the tool and some other tips here: http://code.google.com/speed/page-speed/docs/using.html

like image 25
Aishwar Avatar answered Oct 27 '22 22:10

Aishwar