How sling add script js included in JSP | Community
Skip to main content
AdobeID24
Level 5
Oct 11, 2019 6:30 AM UTC
Solved

How sling add script js included in JSP

Suppose I am having one component which is having one jsp file and that jsp file having code like

<script type="text/javascript" src="js/inline/polyfills.bundle.js">

how sling will get the js file ....it is taking by default libs/somefolder/js/inline/polyfills.bundle.js.....

bt if i have made chnages in polyfills.bundle.js and overlay the modes from libs to apps like apps/somefolder/js/inline/polyfills.bundle.js .

at run time sling will pick app js as we know sling will search first in libs then it ll look into libs ......but in my case it is taking from libs only after doing that as well.

What I am doing wrong here any idea ?

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Ankur_Khare
Ankur_KhareAccepted solution
New Participant
Oct 11, 2019 7:00 AM UTC

instead of including script like above as it's not the correct way of including js files , could you try something like below in your jsp file-

<ui:includeClientLib categories="cq.jquery"/>

The category will be your clientlib folder.

For more details refer below-

Using Client-Side Libraries

5 replies

AdobeID24
AdobeID24Author
Level 5
Oct 11, 2019 6:37 PM UTC

ok fine ...thanks for your reply

Translate
Ankur_Khare
New Participant
Oct 11, 2019 5:52 PM UTC

We are answering your specific question only.

Please use the include clientlib syntax to include js file instead of script tag so tgat your js gets called instead of libs.

Hope this makes sense.

Translate
AdobeID24
AdobeID24Author
Level 5
Oct 11, 2019 12:51 PM UTC

Its OOTB jsp.... I am trying to cahnge the OOTB functionalities.......Alll above syntax I am aware .please help me on my specific question

Translate
Employee
Oct 11, 2019 12:17 PM UTC

Yes, always use categories. For sly you can use the following syntax:

data-sly-call="${clientlib.js @ categories='clientlib1,clientlib2'}"

Translate
Ankur_Khare
Ankur_KhareAccepted solution
New Participant
Oct 11, 2019 7:00 AM UTC

instead of including script like above as it's not the correct way of including js files , could you try something like below in your jsp file-

<ui:includeClientLib categories="cq.jquery"/>

The category will be your clientlib folder.

For more details refer below-

Using Client-Side Libraries

Translate