Lazy loading Stimulsoft scripts in Angular

Stimulsoft Reports.JS discussion
Post Reply
mrapi
Posts: 277
Joined: Sat Dec 20, 2008 1:08 am

Lazy loading Stimulsoft scripts in Angular

Post 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
HighAley
Posts: 8431
Joined: Wed Jun 08, 2011 7:40 am
Location: Stimulsoft Office

Re: Lazy loading Stimulsoft scripts in Angular

Post 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
mrapi
Posts: 277
Joined: Sat Dec 20, 2008 1:08 am

Re: Lazy loading Stimulsoft scripts in Angular

Post by mrapi »

for our project your product works with Angular 7
thanks
Lech Kulikowski
Posts: 6243
Joined: Tue Mar 20, 2018 5:34 am

Re: Lazy loading Stimulsoft scripts in Angular

Post by Lech Kulikowski »

Hello

Thank you for the information.
mrapi
Posts: 277
Joined: Sat Dec 20, 2008 1:08 am

Re: Lazy loading Stimulsoft scripts in Angular

Post 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
Lech Kulikowski
Posts: 6243
Joined: Tue Mar 20, 2018 5:34 am

Re: Lazy loading Stimulsoft scripts in Angular

Post by Lech Kulikowski »

Hello,

Thank you for the provided solution.
Post Reply