Reputation: 28753
Let's say I have CSS that looks like this:
#element {background-image: url("image1.png");}
#element {background-image: url("image2.png");}
Will the browser:
Upvotes: 3
Views: 107
Reputation: 10012
If you implement a website running this in chrome you can see that the browser parses the CSS first, creates the rules & requests it needs then makes the request.
In CSS rules at the bottom of the CSS override any from the top, so the browser knows to only request images that are the final rules.
Upvotes: 0
Reputation: 43823
From some quick testing with Chrome and the Developer Tools:
#element
does not exist then neither image is downloaded, since the browser has no matching element to apply the style to#element
exists the usual CSS cascading and specificity rules apply and only image2.png
will be downloaded since that rule appears after the image1.png
rule.That said, other browsers may behave differently.
Upvotes: 1
Reputation: 14575
It parses the CSS first, and then requests the image, so image1.png would not be downloaded
Upvotes: 3
Reputation: 238
When you first request a page, your browser sends arequest to the server, as you know. The browser then starts parsing the page.
When it finds a reference to an external resource, it will do yet another request for that resource. So I think that it will still load it.
Upvotes: -1