Any ideas on including multiple scripts sustainably? #922
-
|
For context, I have a few custom widgets that I've made dynamic through scripts. Basically something that looks like this: document:
head: |
<script>
document.getElementById(`my-custom-widget`).textContent = "New value";
</script>
# ...
pages:
# ...
widgets:
- type: custom-api
# ...
template: |
<div id="my-custom-widget">Initial value</div>I've used the handy document:
$include: scripts/head.yml
# ...
pages:
# ...
widgets:
- $include: widgets/my-custom-widget.ymlSo far so good. However, as I make more of my own widgets dynamic, the
The only solution I've come up with is to do more or less what's documented here: https://github.com/glanceapp/glance/blob/main/docs/configuration.md#document, e.g. document:
head: |
<script src="scripts/my-custom-script-1.js"></script>
<script src="scripts/my-custom-script-2.js"></script>
<script src="scripts/my-custom-script-3.js"></script>This should work in theory, but requires hosting a file server, since in this implementation the client performs additional fetches. I think this is fine, but since for each additional line of code, maintainability decreases much faster than document size increases, it'd be nice to just bundle these with the initial fetch in a similar way that just dumping all the scripts under Just wondering if anyone has any clever ideas on how to do this or if one of my assumptions are wrong 😄 |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
|
I made the HTML Script Loader here: https://github.com/ralphocdol/glance-micro-scripts With this, you can bundle the script with the widget. Also,
I'm not sure what you meant by this as you don't necessarily need to host a file server since Glance has one called |
Beta Was this translation helpful? Give feedback.
I made the HTML Script Loader here: https://github.com/ralphocdol/glance-micro-scripts
With this, you can bundle the script with the widget.
Also,
I'm not sure what you meant by this as you don't necessarily need to host a file server since Glance has one called
assets-path.