djpogo / lazy-scripts

like you do with lazy loaded images, lazy load, parse and execute your js
GNU General Public License v3.0
1 stars 0 forks source link

Using Lazy-Scripts with Swup #11

Open sixtillnine opened 3 years ago

sixtillnine commented 3 years ago

I'm trying to get Lazy-Scripts working with swup. However it doesn't run on the content replaced function, any ideas how this could be implemented?

The code I'm using is as follows:

swup.on('contentReplaced', function () {
    new LazyScripts();
});
djpogo commented 3 years ago

Hi @sixtillnine,

I might need more information about that. I think the MutationObserver added in version 0.3.0 should help you. You need to load and start LazyScripts() direct in your page and than it should recognize DOM changes directly.

In the demopage there is an element added by JavaScript to the page and LazyScripts takes care of it.

kind regards, Raoul