# Load a library before a component starts

> List scripts and styles as the dependencies of a component so jComponent downloads them once and starts the component afterwards.

Framework: jcomponent20
Product: jComponent 20 (jcomponent@20)
Language: en
Content-SHA256: 1343e12a6dec77d0fadee875a09f8a990ec5f2291032789c23e3d9ad97689498
Snapshot: c0700e321579725c5cf4f5ace1ad7d2866d1b4f93c24a63c0b41b6b7998e976c
Sources: jcomponent20@3fedd009a277f50fddc608b97afbec553b67c51b
Review: not-recorded

The fourth argument of `COMPONENT()` is a list of **dependencies**: URLs of scripts (`.js`) or styles (`.css`) that the component needs. jComponent downloads each one only once, in order, and creates the component after they are loaded, so `make()` can rely on the library being there. This is the way to wrap a third-party library into a component without loading it on pages that do not use it.

```js public/js/starslib.js
window.starslib = {
	render: function(count) {
		var html = '';
		for (var i = 0; i < count; i++)
			html += '<span class="star">*</span>';
		return html;
	}
};
```

```html public/index.html
<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8" />
	<title>jComponent</title>
	<link rel="stylesheet" href="//cdn.componentator.com/spa.min@20.css" />
	<script src="//cdn.componentator.com/spa.min@20.js"></script>
</head>
<body>
	<ui-component name="stars" config="count:3"></ui-component>

	<script>

		COMPONENT('stars', 'count:5', function(self, config) {

			self.make = function() {
				// starslib.js was loaded before make()
				self.html(window.starslib.render(config.count));
			};

		}, ['/js/starslib.js']);

	</script>

</body>
</html>
```
