Load specific JS script on page load for every page in AEM just like Java Filters | Community
Skip to main content
Level 2
July 18, 2024
Solved

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

  • July 18, 2024
  • 2 replies
  • 1431 views

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  

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 aanchal-sikka

@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-libs-using-editable-template/m-p/369053/highlight/true#M19298 

2 replies

MukeshYadav_
Community Advisor
Community Advisor
July 18, 2024

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

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

 

Thanks,

sr1045Author
Level 2
July 18, 2024

Thanks @mukeshyadav_ 

aanchal-sikka
Community Advisor
aanchal-sikkaCommunity AdvisorAccepted solution
Community Advisor
July 18, 2024

@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-libs-using-editable-template/m-p/369053/highlight/true#M19298 

Aanchal Sikka
sr1045Author
Level 2
July 18, 2024

Thanks @aanchal-sikka