Problems with using Javascript use api scripts | Community
Skip to main content
Level 2
July 29, 2021
Solved

Problems with using Javascript use api scripts

  • July 29, 2021
  • 2 replies
  • 2143 views

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?

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by Kishore_Kumar_

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)

2 replies

Level 2
July 30, 2021

@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
August 9, 2021
@sprince1504, nice answer. Good to have AEM SMEs like you here. Looking forward to more contribution from you.
Kautuk Sahni
Kishore_Kumar_
Kishore_Kumar_Accepted solution
Level 9
August 7, 2021

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)