6

Let's say we have a page with the some simple HTML/CSS like below. Does the browser also read .b and .c in the stylesheet?

HTML

<div class="a">1</div>
<div>2</div>
<div>3</div>

CSS

.a { color: aqua; }
.b { color: blue; }
.c { color: cyan; }

That is just an example, but in the real world there might be hundreds, thousands lines of CSS code isn't being used, such as using Bootstrap for a very very small project.

Stickers
  • 75,527
  • 23
  • 147
  • 186
  • 3
    Yes, all the rules are read and loaded into memory. Hence why people try to minify their rules and eliminate the redundancies. – j08691 Feb 19 '15 at 20:44
  • This is not exactly a duplicate, but you migth be interested on [this question](http://stackoverflow.com/questions/460389/browser-caching-of-css-files) about CSS cache – Yerko Palma Feb 19 '15 at 20:50

1 Answers1

4

Yes all the rules are loaded in the memory, this is why when you add new element to your DOM (e.g. by using javascript) you see that the style automatically applies to them.

Stickers
  • 75,527
  • 23
  • 147
  • 186
Almis
  • 3,684
  • 2
  • 28
  • 58