Having trouble using Barba.js and separate JS files

734 views Asked by At

I've setup Barba.js on my Wordpress website. It seems to be working. the only thing is that when I transition to other pages, my other JS files don't load until a hard refresh.

I think to solve this, I have to use namespace and BeforeEnter and re-run my separate JS file within that

The only problem is I don't know how to do that. I've looked all over the net.

I've tried this (which I know is not right, but maybe on the right track?)

let script = document.createElement('script');
script.src="/flickity.init.js";   
next.container.appendChild(script);

Any help would be appreciated :)

Thanks in advance!

1

There are 1 answers

0
ddizzle On

Was actually a pretty simple fix.

I just wrapped my other JS files code in a const runScripts = function () {} then called the function runScripts() inside a view in my custom Barba script with beforeEnter({ next }) {} and a relevant name space.