shaack / bootstrap-cookie-consent-settings

A modal dialog (cookie banner) and framework to handle the German and EU law about cookies in a website. Needs Bootstrap.
MIT License
40 stars 15 forks source link

Async loading of lang file #4

Closed skywarth closed 1 year ago

skywarth commented 1 year ago

Today while I was implementing this package into some project, I ran into some problem. Occasionally the modal won't load at all with no errors present in console. It would just display half-transparent black overlay background but the modal is not displayed at all. Upon close inspection, I noticed modal content is not loaded neither. But to my surprise, no errors/exceptions present.

Here's the steps I attempted to resolve the issue:

 function fetchContent(lang, callback) {
        const request = new XMLHttpRequest()
        request.overrideMimeType("application/json")
        const url = self.props.contentURL + '/' + lang + '.json'
        // FOCUS START
        request.open('GET', url, true); //changed to false to resolve the issue 
        // FOCUS END

Third parameter on XMLHttpRequest.open is for async XHR request.

An alternative approach to load language config directly from a js variable would be efficient IMO.

shaack commented 1 year ago

Hi, thanks for you contribution, but don't really understand your explanation, as it works with the current code without any problems on the demo site: https://shaack.com/projekte/bootstrap-cookie-consent-settings/examples/cookie-banner-example.html What is the difference to your version?