2

I have decided to use PJAX namely Barba js plugin . It works great but i have a problem and really need to reinitialize a bunch of js plugins on PJAX ready .

I have tried the following code basically it is from Barba js 1.0 where i use the dispatcher and specify on NewPage Ready create a new script element and append it to the head of the document .

But it doesn't reinitialize or reload the jquery plugin.

am i missing something or is this not the correct way to reinitialize my files ?

         Barba.Dispatcher.on('newPageReady', function (currentStatus, 
          oldStatus, container) {

            alert("the alert works ");

            var importeda = document.createElement('script');
            importeda.src ='..js/jquery-1.8.3.js';
            document.head.appendChild(importeda);

  } );
Mikhail Zhuikov
  • 1,213
  • 2
  • 9
  • 19
user3548161
  • 119
  • 5
  • 18
  • Have you tried a different approach to load the javascript file? https://stackoverflow.com/questions/950087/how-do-i-include-a-javascript-file-in-another-javascript-file#answer-950146 – Honsa Stunna Jul 24 '19 at 12:01
  • Provide HTML structure which includes barba container and placement of the script tags – User863 Jul 24 '19 at 14:23
  • User863 the structure is this html https://barba.js.org/v1/demo/nextprev/index.html except for theres jquery and other scripts loaded after the barba js . if you go to page 2 from page one than back .. thats when the scripts will need to be reinitialized ... since pjax is used. – user3548161 Jul 27 '19 at 00:51
  • @user3548161 why not placing the jquery outside the `barba` container. and load other scripts as [here](https://stackoverflow.com/a/54360910/8053274) – User863 Jul 27 '19 at 14:03

0 Answers0