简体   繁体   中英

Having trouble using Barba.js and separate JS files

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!

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM