A bunch of widgets that can be embedded into other website (ie. Webflow). These widgets have developed as client-side rendered React applications.
- jsDelivr: free CDN for hosting the application files
- Index's API: provides the data that powers these charts.
- Create feature branch and develop feature.
- When development is complete,
yarn build
and also commit the artifactdist/index-web-widgets.js
. - Review and merge into
main
. - Create a new tag and release in Github.
- Generate a new CDN URL with (jsDelivr Github tool)[https://www.jsdelivr.com/github].
- https://github.com/IndexCoop/index-web-widgets/blob/1.0.0/dist/index-web-widgets.js
- https://cdn.jsdelivr.net/gh/IndexCoop/[email protected]/dist/index-web-widgets.js
- Update the script src for the website with the new CDN URL. See Webflow set up for more details.
This application is a single JavaScript file hosted on jsDelivr.
# Install external dependencies
yarn install
# Start local instance of the application
yarn start
# Lint
yarn lint:fix
# Compile code for production
yarn build
# Deploy built code
yarn deploy
# Combination on build and deploy
yarn build-deploy
- Add a new component in the
/src/widget
directory - Append the new component to the
app.js
switch statement - Append the new component to the
/dist/index.html
to view the component
A. Insert this widget library so that it is available for the entire site.
- From your site, go to
Site settings
from the menu - Go to
Custom Code
section - In the
Footer code
section insert the script like the following:
<!-- S3 hosting -->
<script src="https://<bucket>.s3.<region>.amazonaws.com/bundle.js"></script>
<!-- jsDelivr hosting -->
<script src="https://cdn.jsdelivr.net/gh/IndexCoop/[email protected]/dist/index-web-widgets.js"></script>
B. Inserting a widget
- Add Element > Advanced > Embed
- Add custom code for one of the following widgets you would like to insert
<!-- Token Allocation (Pie Chart) -->
<div class="index_web_widget" data-widget-type="chart-token-allocation" data-token-symbol="DPI"></div>
<div class="index_web_widget" data-widget-type="chart-token-allocation" data-token-symbol="MVI"></div>
<div class="index_web_widget" data-widget-type="chart-token-allocation" data-token-symbol="BED"></div>
<!-- Price (Line Chart) -->
<div class="index_web_widget" data-widget-type="chart-token-line" data-token-symbol="DPI"></div>
<div class="index_web_widget" data-widget-type="chart-token-line" data-token-symbol="MVI"></div>
<div class="index_web_widget" data-widget-type="chart-token-line" data-token-symbol="BED"></div>
C. Publish Site To Review Changes
- add unit test
Webflow does not host JavaScript files. While we can directly embed JS code, there are character limits so this is only feasible for small snippets.
Hosting widgets with iframes is one option but requires the application to be hosted somewhere. Unless we already have the infrastructure set up for this, this option is probably not worth it.
My proposed option at the moment, is to develop our widgets in React. The main reason for this is because React is a dependency for the charting library we will likely use. The Webflow app can then incorporate our externally host JS code with <script/>. For this option, the JS code needs to be publicly available.
Private S3
We could host our code with AWS S3. The current deployment relies on AWS CLI ran locally but this could be enhanced to run in some future CI/CD pipeline.
- ✓ self-hosted means greater control
- x self-hosted means we bear to cost of maintenance (fiat and time)
jsDelivr (CDN)
- ✓ Free
- ✓ No set up
- ✓ Supports versioning
- ? Availability, to be confirmed but should be high
- X Relying on a third party service provider
Determine CDN link with their online tool here: https://www.jsdelivr.com/github
Commited file: https://github.com/TheodoreChuang/index-web-widgets/blob/1.0.0/dist/index-web-widgets.js -> CDN automatically available at: https://cdn.jsdelivr.net/gh/TheodoreChuang/[email protected]/dist/index-web-widgets.js
We will need to either use release versions or somehow invalid their cache if we don't; otherwise, updates to the same compile files will not get reflected.