The browser will try to load each stylesheet, of course, if it has already been loaded and cached, then it will no longer be loaded (but it will analyze it).
I assume that you do not want to place it on the main page, because you have several components, and each of them has its own stylesheet (then you do not want to load them all using only a few components).
The performance impact should be quite small (both when parsing and when applying the same stylesheet), but if you do one of the following:
- You delete CSS classes in several stylesheets (because patches of other CSS files will be overwritten);
- You do some tricks with your style sheets (for example,
$("#linkId").attr("href", "/example.com/override.css"); ); - You change them programmatically;
- You rely on client-side LESS parsing (with
type="text/less" ).
Then you can avoid replacing (see also jQuery: add dom element if it does not exist ):
<script type="text/javascript"> if ($("link[href='/example.com/component.css']").length == 0) $("<link href='/example.com/component.css' rel='stylesheet'/>").appendTo("head"); </script>
Alternatively, you can use id (instead of checking with href ). Note: if you do this often, you can write a helper function.
source share