Liam_or
<script> tags in heex and app.js
I’m having difficulty understanding where JS can belong in a liveview app. I understand that JS hooks belong in app.js, but there is only one app.js which means every hook you write, will be bundled and sent to the client. For universal hooks that would be ok, but for component specific js, if a client never navigates to a view which uses it, it would lead to unused JS being sent to the client. It would be lovely to be able to write JS in the heex, and it appears to be possible, but is it safe to write component specific JS within tags in heex?
Most Liked
frankdugan3
LostKobrakai
For now you’d have something like this
{
mounted() {
this.loading = true;
import("heavy_dep")
.then(dep => {
this.loading = false;
# start using dep
# assign stuff to this for use in other hook callbacks
# …
})
},
…
}
Depending on the bundler used this should generate additional js files, which are only loaded once that import function is called.
Lucassifoni
I’m bumping this as I see that Colocated hooks are in the works : Colocated Hooks by SteffenDE · Pull Request #3705 · phoenixframework/phoenix_live_view · GitHub
The fact that there will be a bundling/runtime distinction seems perfect to me and covers my use cases well. This would enable loading Liveview apps at runtime without hacks.
Huge thanks to SteffenD and the Phoenix team, this will be a real enabler.
Popular in Questions
Other popular topics
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #websockets
- #supervisor
- #advent-of-code
- #elixirconf-us
- #distillery
- #processes
- #forms
- #api
- #metaprogramming
- #security
- #performance








