BON Loyalty Widget and Single Page Application (SPA)

One of the issues with SPA (Single Page Application) is the website does not refresh after user authentication (login/register). Our authentication is running on the server side, and it takes effect only when page is refreshed!

The walk-around code below should help BON Loyalty Widget work well with SPA.

After the customer is authenticated (login/register) successfully on the website, run the following code snippet to re-initiate our widget to enable the customer authentication together with the BON Loyalty Widget.

function createjscssfile(filename){
    var fileref=document.createElement('script')
    fileref.setAttribute("type","text/javascript")
    fileref.setAttribute("src", filename)
    return fileref
}
 
function replacejscssfile(oldfilename, newfilename){
    var allsuspects=document.getElementsByTagName("script")
    for (var i=allsuspects.length; i>=0; i--){ //search backwards within nodelist for matching elements to remove
        if (allsuspects[i] && allsuspects[i].getAttribute("src")!=null && allsuspects[i].getAttribute("src").indexOf(oldfilename)!=-1){
            var newelement=createjscssfile(newfilename)
            allsuspects[i].parentNode.replaceChild(newelement, allsuspects[i])
        }
    }
}

window.bonRender = false;
replacejscssfile("https://d31wum4217462x.cloudfront.net/app/bon-loyalty.js?v=3.2.0", "https://d31wum4217462x.cloudfront.net/app/bon-loyalty.js?v=3.2.0" + new Date().valueOf()) //Replace all occurences of "oldscript.js" with "newscript.js"