# Are all dependencies imported when I import another notebook?

**URL:** <https://talk.observablehq.com/t/are-all-dependencies-imported-when-i-import-another-notebook/1433>\
**Category:** Feedback\
**Created:** [November 27, 2018, 12:41pm UTC](https://talk.observablehq.com/t/are-all-dependencies-imported-when-i-import-another-notebook/1433 "2018-11-27T12:41:27Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Job](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.observablehq.com/job/32/1185_2.png) [@Job](https://talk.observablehq.com/u/Job)\
**Post date:** [November 27, 2018, 12:41pm UTC](https://talk.observablehq.com/t/are-all-dependencies-imported-when-i-import-another-notebook/1433/1 "2018-11-27T12:41:27Z")

</div>

So I was thinking it would be quite easy for me to create some small WASM functions using Walt. The output would be really small binary blobs. But the notebook in question would have to download the whole Walt toolchain.

So if I import the function into another notebook - effectively just a single cell in said notebook - would that fetch just that cell, or the whole notebook + dependencies?

Put another way: lots of JS libraries have a minified distribution version. Do notebooks support something similar?

---

<div class="post-metadata">

**Author:** ![bgchen](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.observablehq.com/bgchen/32/784_2.png) [@bgchen](https://talk.observablehq.com/u/bgchen)\
**Post date:** [November 27, 2018, 4:05pm UTC](https://talk.observablehq.com/t/are-all-dependencies-imported-when-i-import-another-notebook/1433/2 "2018-11-27T16:05:28Z")

</div>

Yes, importing a cell from a notebook in Observable does import all of its dependencies. Consider for example the tutorial notebook itself:

> **[Imports | Observable documentation](https://observablehq.com/@mbostock/introduction-to-imports)**
>
> All your Observable questions answered

The imported charts / graphics each use their own independent copies of `d3`. In particular, the `d3 = require("https://d3js.org/d3.v5.min.js")` cell at the bottom is actually unused (you can check this by commenting out the cell and observing that the notebook still works).

Also, according to that tutorial:

> You can import the same notebook multiple times and references will resolve exactly.

The same should hold true for their dependencies, so I think this means you won’t have to worry about creating multiple copies of `require` statements when importing from the same notebook.

---

<div class="post-metadata">

**Author:** ![mbostock](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.observablehq.com/mbostock/32/9_2.png) [@mbostock](https://talk.observablehq.com/u/mbostock)\
**Post date:** [November 27, 2018, 4:51pm UTC](https://talk.observablehq.com/t/are-all-dependencies-imported-when-i-import-another-notebook/1433/3 "2018-11-27T16:51:41Z")

</div>

Importing a notebook fetches the code for the imported notebook in its entirety, and then runs the cells that were explicitly imported along with their transitive dependencies.

If you import a single cell from a notebook, and that cell depends on other cells in that notebook, the imported cell and all its dependencies are run. However, other cells in that notebook that are not depended upon by the imported cells are not run.

(Eventually, we may optimize the import implementation so that it only fetches the necessary subset of the code, too. And maybe we’ll even minify…)

---

<div class="post-metadata">

**Author:** ![mbostock](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.observablehq.com/mbostock/32/9_2.png) [@mbostock](https://talk.observablehq.com/u/mbostock)\
**Post date:** [November 27, 2018, 4:52pm UTC](https://talk.observablehq.com/t/are-all-dependencies-imported-when-i-import-another-notebook/1433/4 "2018-11-27T16:52:09Z")

</div>

I removed the unused `d3` cell from this notebook. Thanks for noticing!

---

<div class="post-metadata">

**Author:** ![Job](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.observablehq.com/job/32/1185_2.png) [@Job](https://talk.observablehq.com/u/Job)\
**Post date:** [November 28, 2018, 11:20am UTC](https://talk.observablehq.com/t/are-all-dependencies-imported-when-i-import-another-notebook/1433/5 "2018-11-28T11:20:13Z")

</div>

> [@mbostock](#):
>
> Importing a notebook fetches the code for the imported notebook in its entirety, and then runs the cells that were explicitly imported along with their transitive dependencies.

I figured, since it’s the technically easiest approach to start out with.

> [@mbostock](#):
>
> If you import a single cell from a notebook, and that cell depends on other cells in that notebook, the imported cell and all its dependencies are run. However, other cells in that notebook that are not depended upon by the imported cells are not run.

Ah, so there already is _some_ benefit already to having manually inlined/minified cells at least! Good to know

> [@mbostock](#):
>
> (Eventually, we may optimize the import implementation so that it only fetches the necessary subset of the code, too. And maybe we’ll even minify…)

I mean, you don’t want `event-stream` shenanigans so this is part of an important larger puzzle to figure out I guess
