Skip to content

Commit d1a4903

Browse files
committed
more docs
1 parent c4820ca commit d1a4903

File tree

1 file changed

+34
-19
lines changed

1 file changed

+34
-19
lines changed

Diff for: docs/source/javascript-components.rst

+34-19
Original file line numberDiff line numberDiff line change
@@ -105,23 +105,44 @@ Distributing Javascript Components
105105

106106
There are two ways that you can distribute your :ref:`Custom Javascript Components`:
107107

108-
- In a Python package via PyPI_
109108
- Using a CDN_
109+
- In a Python package via PyPI_
110+
111+
These options are not mutually exclusive though, and it may be beneficial to support
112+
both options. For example, if you upload your Javascript components to NPM_ and also
113+
bundle your Javascript inside a Python package, in principle your users can determine
114+
which work best for them. Regardless though, either you or, if you give then the choice,
115+
your users, will have to consider the tradeoffs of either approach.
116+
117+
- :ref:`Distributing Javascript via CDN_` - Most useful in production-grade applications
118+
where its assumed the user has a network connection. In this scenario a CDN's `edge
119+
network <https://en.wikipedia.org/wiki/Edge_computing>`__ can be used to bring the
120+
Javascript source closer to the user in order to reduce page load times.
121+
122+
- :ref:`Distributing Javascript via PyPI_` - This method is ideal for local usage since
123+
the user can server all the Javascript components they depend on from their computer
124+
without requiring a network connection.
125+
126+
127+
Distributing Javascript via CDN_
128+
................................
110129

111-
These options are not mutually exclusive though - if you upload your Javascript
112-
components to NPM_ and also bundle your Javascript inside a Python package, in principle
113-
your users can determine which option work best for them. Regardless though, either you
114-
or, if you give then the choice, your users, will have to consider the tradeoffs of
115-
either approach.
130+
Under this approach, to simplify these instructions, we're going to ignore the problem
131+
of distributing the Javascript since that must be handled by your CDN. For open source
132+
or personal projects, a CDN like https://unpkg.com/ makes things easy by automatically
133+
preparing any package that's been uploaded to NPM_. If you need to roll with your own
134+
private CDN, this will likely be more complicated.
116135

117-
- Distribution via PyPI_ - This method is ideal for local usage since the user can
118-
server all the Javascript components they depend on from their computer without
119-
requiring a network connection.
136+
In either case though, on the Python side, things are quite simple. You need only pass
137+
the URL where your package can be found to :func:`~idom.web.module.module_from_file`
138+
where you can then load any of its exports:
120139

121-
- Distribution via a CDN_ - Most useful in production-grade applications where its assumed
122-
the user has a network connection. In this scenario a CDN's
123-
`edge network <https://en.wikipedia.org/wiki/Edge_computing>`__ can be used to bring
124-
the Javascript source closer to the user in order to reduce page load times.
140+
.. code-block::
141+
142+
import idom
143+
144+
your_module = ido.web.module_from_file("https://some.cdn/your-module")
145+
YourComponent = idom.web.export(your_module, "YourComponent")
125146
126147
127148
Distributing Javascript via PyPI_
@@ -367,12 +388,6 @@ creating your custom components using the provided `template repository`_ so you
367388
up and running as quickly as possible.
368389

369390

370-
Distributing Javascript via CDN_
371-
................................
372-
373-
Under construction...
374-
375-
376391
.. Links
377392
.. =====
378393

0 commit comments

Comments
 (0)