axelson
Scenic Core Team
One of my LiveView view’s has a very heavy javascript dependency so I want to avoid loading it for every page on the site, while still using live_redirect or similar between the two (avoiding a full-page load). However, I’m running into
https://github.com/patrick-steele-idem/morphdom/issues/178
This means that any <script> tag that I put into the page will not be executed. Of course there are a plethora of work-arounds: https://stackoverflow.com/questions/2592092/executing-script-elements-inserted-with-innerhtml But I figured that someone else has probably tried to solve this before so I am curious what other people have tried or are using.
Trending in Questions
Hey guys,
I’ve got a huge CSV ( around 10 GB ) that needs to be processed hourly
Do you guys have any suggestions what is the best prac...
New
Hello!
Could someone please give me a help/sample code, how to delete a file from s3 using waffle/waffle_ecto from Phoenix app.
I creat...
New
I’m seeing that a list inside a Kino.DataTable will be interpreted as a charlist, even if the Kino.configure() is set to charlists: :as_l...
New
So my question is quite simple and i have found no conclusive answer on forum, google or AI.
Should we use :erlang.float for Integer to ...
New
Hi, I’ve just set up an application with ash_authentication. There is only magic link strategy for now, so there is no confirmation add o...
New
If a change or preparation module uses Ash.Changeset.get_argument/2 or Ash.Query.get_argument/2 (or any of the other get_argument functio...
New
I’m trying to set up Emacs with elixir-ls via lsp-mode and credo via Flycheck. This should mostly be preconfigured as Flycheck picks up c...
New
Other Trending Topics
I am happy to introduce the very α version of the new programming language compiled to BEAM.
Welcome Cure.
It has literally three kille...
New
Hobbes is a low-level distributed database for the Elixir programming language.
Hobbes provides a simple, safe, and scalable storage lay...
New
Hi there! We created Gust: A task orchestrator inspired by Airflow.
For those who have never heard about Aiflow, it’s a Python-based wor...
New
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
ExRatatui lets you cook up rich terminal UIs in Elixir, powered by Rust’s ratatui via Rustler NIFs. Build interactive terminal applicatio...
New
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge & Solve.
They are GUI (Emerge) and State management (S...
New
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
- #elixirconf
- #channels
- #exunit
- #discussion
- #code-sync
- #podcasts
- #javascript
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #blog-post
- #elixirconf-us
- #elixir-ls
- #ai
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #hex
- #security
- #metaprogramming











Showing Posts 1 to 10- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
Bumppoman
Any chance you might be able to load it with a hook?
dbern
I was able to do it via a LiveView hook and webpack’s dynamic imports.
Now, if you figure out
<head>tags please let me know. I want LiveView-enabled pages but with opengraph+friends tags based on a resource loaded on mount. I don’t think I can use hooks/JS for that.axelson
I kind of can but it feels overly hacky. The approach that I’ve come to that partially works is to have a LiveComponent that receives the
srchref as an assign. Then it creates a<script src="<%= @src %>" onload="onloadfunc()"></script>whereonloadfunciswindow.loadedScripts = window.loadedScripts || {}; window.loadedScripts['<%= @src %>'] = true. Then in the hook it checks if the script with the currentsrchas been loaded, and if not it usesdocument.createElement('script')along withappendChildto load the script. I’m not yet sure about pushing it to production.Hmm, I’m just using separate bundles but not dynamic imports. Do you have an example you could share about how that worked for you? And are you actually using webpack 5.0 (that’s the version of the docs you linked to)?
dbern
I’m using Webpack 4.43.0. I didn’t notice the docs are for v5, but the dynamic imports are certainly working for me.
I’m going to open-source YouMeet when it launches, so I don’t have the full repo open to browse yet, but here are some snippets that I think covers it.
Here’s an example hook to load a fancy WYSIWYG editor that’s using Vue:
On the LiveView EEX to load it (actually a LiveComponent but should be about the same)
and in my Webpack config:
EDIT: There should be a GIF right here, but it doesn’t seem to load? Sorry, it’s just illustrating how navigating from one LiveView without the script, and then clicking a link to another liveview does trigger the JS fetch and import.

Hopefully I didn’t miss anything!
polypush135
What I’ve learned is that if you are using webpack you should be able to dynamically load bundles per hook.
This is how I’m currently doing it.
By using this style in importing.
It only works if you import this way.
idi527
Not sure if it’s relevant, but: Has anyone used lazy loading in a phoenix live view project?
And the example repo: https://github.com/syfgkjasdkn/lazy-live-view
axelson
Thanks for all the examples. I should be able to get something working with them.
dbern
Here’s the gif I tried to post earlier: https://imgur.com/a/izmruiM
polypush135
That’s a cool way of using async function for hooks.
Thanks for sharing that exmaple.
rhcarvalho
This is one of the two best threads that come up from search on the topic, so reviving it with an up-to-date solution for the benefit of all.
Just like the OP, I wanted to use a heavy JS library in a single page without compromising the bundle size for the rest of the app.
Nowadays Phoenix projects use
esbuildby default, and modern browsers support ESM modules and dynamic import.To my surprise, asking Gemini 3 produced a reasonable output, hinting at the right things. In a nutshell:
config/config.exsto output the bundle as an ESM module and enable code-splitting:app.jsas a module:mount()callback.With that setup,
esbuildshould produce a small bundle forapp.js, loaded on all pages, and additional files that are only imported/downloaded/executed when needed.Resources