Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
BedrockMission!

Learn more

View all

Sign in to view all badges

SOLVED

Problems with using Javascript use api scripts

aemAmateur
Level 2
Level 2

I have read from multiple blogs, HTL scripting documentation that JavaScript use scripts are compiled on run time and hence they are slower compared to Java use script and sling model. But I do not understand what does runtime here means, would the JavaScript code be compiled to Sling code when it is called by a component? or Would the code be compiled to Sling code once it is installed to the server? Also, if there is a performance overhead in using JavaScript use script over a Sling model, how big is it?

I have also read in so many questions that use scripts should be restricted to components. But I do not see any problems with use scripts processing data from multiple components as we could pass arguments while calling them. Is there any reason people prefer to restrict use scripts just to a specific component?

1 Accepted Solution
kishorekumar14
Correct answer by
Level 8
Level 8

hi @aemAmateur ,

 

Javascript API is mainly brought in to enable Frond end developers to handle server side logics. We can also use all the JAVA APIs like Resource resolver, Externaliser etc in JS API. AEM internally uses RHINO to convert everything to Java and to make it work. Since the conversion happens in the background, the performance is considered as slow compared to JAVA API.

 

Also there is no debugging facility with JS API unlike JAVA API.

 

I would suggest to use Sling Models as it the preferred way in most of the cases (current recommendation by adobe for SPA and HTL)

View solution in original post

3 Replies
sprince1504
Level 2
Level 2

@aemAmateur 

Use js executes at server level. I usually don't prefer to work on it until and unless there is no option.

mostly people use it if there is any enhancement or customization on authoring.

right now everything is possible with sling models.

  

kautuk_sahni
Community Manager
Community Manager
@sprince1504, nice answer. Good to have AEM SMEs like you here. Looking forward to more contribution from you.
kishorekumar14
Correct answer by
Level 8
Level 8

hi @aemAmateur ,

 

Javascript API is mainly brought in to enable Frond end developers to handle server side logics. We can also use all the JAVA APIs like Resource resolver, Externaliser etc in JS API. AEM internally uses RHINO to convert everything to Java and to make it work. Since the conversion happens in the background, the performance is considered as slow compared to JAVA API.

 

Also there is no debugging facility with JS API unlike JAVA API.

 

I would suggest to use Sling Models as it the preferred way in most of the cases (current recommendation by adobe for SPA and HTL)

View solution in original post