Expand my Community achievements bar.

SOLVED

Load specific JS script on page load for every page in AEM just like Java Filters

Avatar

Level 2

Hello Devs,

I have one requirement where javascript code should load every time for every page.

I went through the clientlibs approach but below challenges I am having with current project -

1. They have multiple page components to Author different type of pages

2. There is no common clientlib i have observed till now which loads for every page

 

Please can anyone guide me what should be the correct approach to deal with such cases.

Thanks  

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

@sr1045 

 

If you utilise the WCM Core Components V2 Page, as your websites base page during the creation of the editable templates, you can utilize the editable template's Page Policies to set specific client libraries for different templates.

 

Please refer to screenshots on https://experienceleaguecommunities.adobe.com/t5/adobe-experience-manager/load-site-specific-client-... 


Aanchal Sikka

View solution in original post

4 Replies

Avatar

Community Advisor

Hi @sr1045 ,

You may target template and add js at template level.

Most probably one page component overridden from core component would be getting used in all the template types( or even you may be having limited number of template)

You can create a clientlib category and can add in customfooterlibs.html of that page component which are getting used in all the template 

PFA

MukeshYadav__0-1721303645557.png

If it just few line of script tag like for gtm etc you can directly tadd that cript in head.html

So based on your use case you can add js centrally which will reflect in all the already created and future pages

MukeshYadav__0-1721305387133.png

 

Thanks,

Avatar

Correct answer by
Community Advisor

@sr1045 

 

If you utilise the WCM Core Components V2 Page, as your websites base page during the creation of the editable templates, you can utilize the editable template's Page Policies to set specific client libraries for different templates.

 

Please refer to screenshots on https://experienceleaguecommunities.adobe.com/t5/adobe-experience-manager/load-site-specific-client-... 


Aanchal Sikka