How to access clientlibs in ui.apps from other js file in ui.frontend | Community
Skip to main content
Level 3
June 27, 2024
Solved

How to access clientlibs in ui.apps from other js file in ui.frontend

  • June 27, 2024
  • 2 replies
  • 932 views

Hello community

 

The code below needs to return an SVG from a folder within clientlibs in ui.apps. However, when I attempt to access it, it returns "<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML...."

 

This SVG will be located in the folder mysite/ui.frontend/src/main/webpack/resources/images, and when built, it generates the same SVG in mysite/ui.apps/src/main/content/jcr_root/apps/project/clientlibs/clientlib-site/resources/images.

When attempting to access directly in /apps in the local environment, it works. However, it does not work in the production environment.

 

I would like to better understand why this is happening and how I can access this folder using this method.

 

const iconsPath = '/src/main/webpack/resources/images';

export async function fetchSvg(value) {
if (!iconCache[value.htmlType]) {

const response = await fetch(`${iconsPath}/${value.htmlType}.html`);
const htmlContent = await response.text();

if (htmlContent) {
iconCache[value.htmlType] = htmlContent;
return { type: value.iconDataType, value: htmlContent };
} else {
throw new Error(`SVG for ${value.htmlType} not found in the HTML content`);
}
} else {
return { type: value.iconDataType, value: iconCache[value.htmlType] };
}

}
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 MukeshYadav_

Hi @nathanvieira ,

We can access resource from clientlibs proxy as /etc.clientlibs/sourcedcode/clientlibs/cllienlib-site/resources/tick.svg

const iconsPath = '/etc.clientlibs/project/clientlib-site/resources/images';

 

Pls have a look https://sourcedcode.com/blog/aem/how-to-serve-static-assets-in-aem-as-client-library-resources

https://experienceleague.adobe.com/en/docs/experience-manager-65/content/implementing/developing/introduction/clientlibs#locating-a-client-library-folder-and-using-the-proxy-client-libraries-servlet

Thanks

2 replies

EstebanBustamante
Community Advisor and Adobe Champion
Community Advisor and Adobe Champion
June 27, 2024
Esteban Bustamante
MukeshYadav_
Community Advisor
MukeshYadav_Community AdvisorAccepted solution
Community Advisor
June 27, 2024

Hi @nathanvieira ,

We can access resource from clientlibs proxy as /etc.clientlibs/sourcedcode/clientlibs/cllienlib-site/resources/tick.svg

const iconsPath = '/etc.clientlibs/project/clientlib-site/resources/images';

 

Pls have a look https://sourcedcode.com/blog/aem/how-to-serve-static-assets-in-aem-as-client-library-resources

https://experienceleague.adobe.com/en/docs/experience-manager-65/content/implementing/developing/introduction/clientlibs#locating-a-client-library-folder-and-using-the-proxy-client-libraries-servlet

Thanks

Level 3
June 28, 2024

Thanks it worked, I was forgetting this part of documentation