Announcement

Collapse
No announcement yet.

External lib like domain.com/lib.js

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • External lib like domain.com/lib.js

    How to use an external library like https://domain.com/lib.js. In version 7, a jsLibs description of "path": "//domain.com/lib.js", was available. Doesn't work in version 8. It might make sense to change https://github.com/espocrm/espocrm/b...loader.js#L902 to
    Code:
    const urlObj = new URL(url, this._baseUrl);

  • #2
    I recommend to find some other way. As it's the very core of the frontend, I'm reluctant to make any changes there unless necessary. I did not plan to have the ability to use external scripts via the loader.

    Comment


    • #3
      For future use, it may be useful:

      Code:
      loadScript: function(src) {
                  return new Promise(function(resolve, reject) {
                      const s = document.createElement('script');
                      let r = false;
                      s.type = 'text/javascript';
                      s.src = src;
                      s.async = true;
                      s.onerror = function(err) {
                          reject(err, s);
                      };
                      s.onload = s.onreadystatechange = function() {
                          // console.log(this.readyState); // uncomment this line to see which ready states are called.
                          if (!r && (!this.readyState || this.readyState == 'complete')) {
                              r = true;
                              resolve();
                          }
                      };
                      const t = document.getElementsByTagName('script')[0];
                      t.parentElement.insertBefore(s, t);
                  });
              },
      
      setup: function (){
                  Dep.prototype.setup.call(this);
      
                  this.wait(
                      this.loadScript('//domain.com/lib.js')
                  );
      }​​

      Comment

      Working...
      X