External lib like domain.com/lib.js

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • dimyy
    Active Community Member
    • Jun 2018
    • 569

    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);
  • yuri
    Member
    • Mar 2014
    • 8627

    #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.
    If you find EspoCRM good, we would greatly appreciate if you could give the project a star on GitHub. We believe our work truly deserves more recognition. Thanks.

    Comment

    • dimyy
      Active Community Member
      • Jun 2018
      • 569

      #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...