Expand my Community achievements bar.

SOLVED

Externalize a URL from a clientlibs script

Avatar

Level 2

Hi all,

Is it possible to access resource mappers and also externalize URLs from a clientlibs javascript that runs on clients browser?


1 Accepted Solution

Avatar

Correct answer by
Community Advisor

Hi @aemAmateur ,

 

The Externalizer or any resource resolver functions are accessible only in the server side, and the Javascript or clientlibs won't have any visibility to them.

 

For your usecase of externalising or shortening the AEM full urls received from a third party, following could be possible solutions:

1. Update the Source (Preferred) : Update the data at the third party with the AEM shortened/externalised URLs and use them as is. Afterall, we wouldn't want to expose the AEM full content paths to a third party, and that should solve your problem, as well as for any other downstream systems using the same third party service.

2. Wrapper Servlet: If 1 is not possible, Have a servlet in AEM that could accept a set of urls as input and return the corresponding shortened URLs. Invoke this servlet in your JS and use the output.

3. JS Utility (Temporary): Have a custom JS utility that replicates the logic of externalise/shortening and use it in your clientlibs. This however will involve maintenance, if there is any update to your logic at server side.

 

Thanks!

View solution in original post

3 Replies

Avatar

Community Advisor

Hi @aemAmateur 

You cannot externalize the URLs for clientlibs as doing so will require modification of the clientlib invocation script and you need to explicitly call the URLs for clientlib that you will need to build on Model class.

 

Instead of that I can suggest of using the domain sharding and the clientlib along with any other assets can be loaded for different domains and can fasten up the page load as well.

You can refer the below link:

https://adobe-consulting-services.github.io/acs-aem-commons/features/utils-and-apis/static-reference...

 

Thanks!

Avatar

Level 2

hi @Asutosh_Jena_ thanks for the reply. but i think you misunderstood my question. sorry for asking such vague question with no detail.

What I actually want to do is, reproduce the logic of Externalizer.externalLink method in user's browser. I have some URLs that i would receive from a third party JSON file, but it would have the long URLs of AEM pages. Now that i receive these URLs directly on client, I wanted to know if there is any javascript object I could use to convert these long URLs to shortened URLs along with hostname.

Avatar

Correct answer by
Community Advisor

Hi @aemAmateur ,

 

The Externalizer or any resource resolver functions are accessible only in the server side, and the Javascript or clientlibs won't have any visibility to them.

 

For your usecase of externalising or shortening the AEM full urls received from a third party, following could be possible solutions:

1. Update the Source (Preferred) : Update the data at the third party with the AEM shortened/externalised URLs and use them as is. Afterall, we wouldn't want to expose the AEM full content paths to a third party, and that should solve your problem, as well as for any other downstream systems using the same third party service.

2. Wrapper Servlet: If 1 is not possible, Have a servlet in AEM that could accept a set of urls as input and return the corresponding shortened URLs. Invoke this servlet in your JS and use the output.

3. JS Utility (Temporary): Have a custom JS utility that replicates the logic of externalise/shortening and use it in your clientlibs. This however will involve maintenance, if there is any update to your logic at server side.

 

Thanks!