Expand my Community achievements bar.

SOLVED

load clientLib based on components(CQ.AUTHORING.DIALOG GETS LOADED ON ALL THE PAGES OR ALL THE PROJECTS)

Avatar

Level 2

we have defined components clientLibs as cq.authoring.dialog, But these js libs will be loaded for all templates(all projects) while authoring the pages.

Can we restrict them based on template or components as these JS may create issue in other AEM projects?

I tried extraClientLibs but its not working properly..

Is there anyway other then overlaying out-of-box components?

Thanks,

Malli

1 Accepted Solution

Avatar

Correct answer by
Level 4

Hi mallipanchal,

I solved this problem by inserting two lines of HTL code in the component HTML itself.  PFA the screenshot:

1544150_pastedImage_0.png

You need to have a clientLibraryFolder created with this category name:

1544151_pastedImage_1.png

Now, ONLY wherever you have this component, the JS/CSS files for this component will be loaded.

Good Luck...

View solution in original post

12 Replies

Avatar

Level 10

In this use case - the best way is to overlay components. If you want to change the style of the overlay component - introduce a new clientlib that contains CSS or JS. This is best practice for AEM. 

Avatar

Administrator

Hi 

Please have a look at this community article for AEM Client Libraries best practices.

If you want to create component specific clientlibs then you need to create a new clientlibs that gets applied to that particular component. See the article to know how to do it.

Link:- http://blogs.adobe.com/experiencedelivers/experience-management/clientlibs-explained-example/

This article will explain:

  • multiple components with their own JavaScript and CSS files
  • global JavaScript and CSS files
  • apps folder is not available on the publish instance
  • CSS resources have to go in the <head>, JavaScript resources at the end of the page
  • Resources need to be minified
  • Some resources need to be merged

I hope this would help you.

~kautuk



Kautuk Sahni

Avatar

Level 2

kautuksahni wrote...

Hi 

Please have a look at this community article for AEM Client Libraries best practices.

If you want to create component specific clientlibs then you need to create a new clientlibs that gets applied to that particular component. See the article to know how to do it.

Link:- http://blogs.adobe.com/experiencedelivers/experience-management/clientlibs-explained-example/

This article will explain:

  • multiple components with their own JavaScript and CSS files
  • global JavaScript and CSS files
  • apps folder is not available on the publish instance
  • CSS resources have to go in the <head>, JavaScript resources at the end of the page
  • Resources need to be minified
  • Some resources need to be merged

I hope this would help you.

~kautuk

 

By this method we can load site specific styles and JS. But I want include TouchUI dialog specific JS in editmode. Currently we used id as cq.authoring.dialog(but these JS loads in all pages or in all project components while editing )

Avatar

Level 10

I spoke to some of our experts - it lines up with my 1st response. 

If not needed for all projects or templates it is better not to attach to cq.authoing.dialog and use cq:includeClientLib with a new category

(introduce a new clientlib that contains CSS or JS.) 

Avatar

Level 7

I've a similar issue, but i fix it just creating a new clientlibrary named custom.authoring.dialog and including it by using extraClientLibs in our components.

Avatar

Level 2

antoniom54959291 wrote...

I've a similar issue, but i fix it just creating a new clientlibrary named custom.authoring.dialog and including it by using extraClientLibs in our components.

 

Yeah, Even I tried this. BUT

Using extraClientlib property on the cq:dialog, This can be done  but issue here is dialog DOM elements and JS lib were loaded at the same point syncing is not happening. so when we open dialog first time its not working, close the dialog and open it again it works fine(JS were loaded in first time, so it works fine second time onwords).

Note: we are using custom-multifield.

Avatar

Level 2

smacdonald2008 wrote...

I spoke to some of our experts - it lines up with my 1st response. 

If not needed for all projects or templates it is better not to attach to cq.authoing.dialog and use cq:includeClientLib with a new category

(introduce a new clientlib that contains CSS or JS.) 

 

 

Where should I include it in page component or in any of the particular components script.( I hope we need this only in EDIT mode)??

Avatar

Level 10

Include the clientlib in the script that corresponds to the component. If its a page component - place it there. 

Avatar

Correct answer by
Level 4

Hi mallipanchal,

I solved this problem by inserting two lines of HTL code in the component HTML itself.  PFA the screenshot:

1544150_pastedImage_0.png

You need to have a clientLibraryFolder created with this category name:

1544151_pastedImage_1.png

Now, ONLY wherever you have this component, the JS/CSS files for this component will be loaded.

Good Luck...

Avatar

Level 4

+ antoniom54959291​, kautuksahni​, smacdonald2008

Hi mallipanchal,

There is one more solution to this. In the client-library that has the category `cq.authoring.dialog`, you can include a sort of name-spacing.  For ex:

1610949_pastedImage_1.png

Good Luck...

Avatar

Level 2

Any way we can segregate libraries depending upon claasic/touch UI

I want to keep both dialogs types in component, but the libraries (custom.js) need to be seperately called in case of touch UI and other s when I open dialog in classic.

Avatar

Community Advisor

For touch UI dialog specific clientlibs you can add via extraClientlibs property

How to Load TouchUI dialog Specific Clientlibs



Arun Patidar