bigskysoftware / bigskysoftware/htmx
Functions in Scripts Do Not Run Automatically When Script is a Module
- Dominant language
- JavaScript
- Stars
- 49.4k
- Forks
- 1.7k
- Avg merge
- 3d 22h
- Merged PRs (30d)
- 30
Description
I am not sure if anyone else is experiencing this issue but when a script with `type="module"` is included in a swap, any function that is generally called in that script does not automatically run. I know that this behaviour is generally solved with an event listener for now, but I wonder if there is a reason for this type of behaviour.
By this I mean, if you have this code:
```
Hi there</div>
<script src="path/to/script/test-script.js" type="module">
```
**test-script.js**
```
function testHi(){
console.log("test-hi")
}
testHi()
```
In this case, test-hi is not printed and nothing is actually printed to the console. This is despite the fact that I can see that htmx has picked up the script. Any additional voices on the best pattern for this kind of behaviour would be greatly appreciated.
Contributor guide
Assessment
This issue has not been assessed yet.