Externalize a URL from a clientlibs script | Community
Skip to main content
Level 2
August 18, 2021
Solved

Externalize a URL from a clientlibs script

  • August 18, 2021
  • 2 replies
  • 945 views

Hi all,

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


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 Fanindra_Surat

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!

2 replies

Asutosh_Jena_
Community Advisor
Community Advisor
August 18, 2021

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-rewriter/index.html

 

Thanks!

Level 2
August 18, 2021

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.

Fanindra_Surat
Community Advisor
Fanindra_SuratCommunity AdvisorAccepted solution
Community Advisor
August 18, 2021

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!