Page 1 of 1

Lazy loading Stimulsoft scripts in Angular

Posted: Tue Apr 23, 2019 9:16 am
by mrapi
Hi,
is there a way to lazy loading Stimulsoft scripts in Angular 7.If I check deployed application I can see in main page source scripts.file:

Code: Select all

   http://myserver../scripts.8896c3ee4599d39adb68.js 
and on first line
"undefined"==typeof Stimulsoft&&(Stimulsoft={});var stimulsoft_reports="UEsDBAoAAAAIAAdYfE5Gl7nz7JwZAIG.........
scripts are loaded in angular.json file

Code: Select all

 "scripts": [
			"src/stimulsoft/stimulsoft.reports.pack.js",
            "src/stimulsoft/stimulsoft.viewer.pack.js"
			]
no Stimulsoft loaded in app.module
thanks

Re: Lazy loading Stimulsoft scripts in Angular

Posted: Fri Apr 26, 2019 5:59 am
by HighAley
Hello.

We didn't test our product in Angular 7.
We will check if it's possible to use lazy loading with our scripts.

Thank you.

Ticket reference: #8207

Re: Lazy loading Stimulsoft scripts in Angular

Posted: Thu May 02, 2019 8:47 am
by mrapi
for our project your product works with Angular 7
thanks

Re: Lazy loading Stimulsoft scripts in Angular

Posted: Fri May 03, 2019 2:44 pm
by Lech Kulikowski
Hello

Thank you for the information.

Re: Lazy loading Stimulsoft scripts in Angular

Posted: Sat May 18, 2019 8:52 am
by mrapi
Hi
We found a solution to lazy load:
removed scripts load from
angular.json
and copy files to
src/assets
folder

then we define inside a general service:

Code: Select all

....
@Injectable()
export class GeneralService {
  private stiScrpLoaded = false;
.....
public loadStimulScripts() {
    if (!this.stiScrpLoaded) {
      this.loadScript("assets/stimulsoft.viewer.pack.js");
      this.loadScript("assets/stimulsoft.reports.pack.js");
      this.stiScrpLoaded = true;
    }
  }
..
  private loadScript(url: string) {
    let node = document.createElement('script');
    node.src = url;
    node.type = 'text/javascript';
    node.async = true;
    node.charset = 'utf-8';
    document.getElementsByTagName('head')[0].appendChild(node);
  }
}
...
now before load every component that show reports need to call ..loadStimulScripts()
now load time is improved specially for mobile devices

Re: Lazy loading Stimulsoft scripts in Angular

Posted: Mon May 20, 2019 11:53 am
by Lech Kulikowski
Hello,

Thank you for the provided solution.