function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Chris VillanuevaChris Villanueva 

Using custom fonts in managed package with LWC

Hello, 

I have added a static resource for custom fonts in .woff format. I am using the static resource in my lightning web compnent in the css file with the following

component.css
@font-face {
    font-family: 'CustomFont';
    src: url('/resource/CustomFont') format('woff');
}

This works perfectly fine when I am working in my development organization. But the issue is when I create a managed beta package and include the component and static resource. 

Once I upload the package and install it in a separate test org, the component is no longer able to find the custom font / static resource. I receive the following error in the browser developer console on Google Chrome
 
GET https://companytestorg.lightning.force.com/resource/CustomFont net::ERR_ABORTED 404 (Not Found)

Can I get some guidance on what I am missing here when it comes to using a static resource custom font in an installed managed package? Thank you!
 
Best Answer chosen by Chris Villanueva
SwethaSwetha (Salesforce Developers) 
HI Chris,
Based on similar posts from past, it appears to be an issue with the referenced URL

Related: https://salesforce.stackexchange.com/questions/204695/custom-fonts-not-working
https://salesforce.stackexchange.com/questions/56897/font-files-in-static-resources-resolve-to-404
https://salesforce.stackexchange.com/questions/38940/is-it-possible-to-access-static-resource-of-a-managed-package-in-a-local-vf-page

Try using the managed package namespace prefix.Something like
<link href="/resource/namespace__resourceName" rel="stylesheet"/>
<ltng:require script="/resource/namespace__resourceName....."/>
If this information helps, please mark the answer as best. Thank you

All Answers

SwethaSwetha (Salesforce Developers) 
HI Chris,
Based on similar posts from past, it appears to be an issue with the referenced URL

Related: https://salesforce.stackexchange.com/questions/204695/custom-fonts-not-working
https://salesforce.stackexchange.com/questions/56897/font-files-in-static-resources-resolve-to-404
https://salesforce.stackexchange.com/questions/38940/is-it-possible-to-access-static-resource-of-a-managed-package-in-a-local-vf-page

Try using the managed package namespace prefix.Something like
<link href="/resource/namespace__resourceName" rel="stylesheet"/>
<ltng:require script="/resource/namespace__resourceName....."/>
If this information helps, please mark the answer as best. Thank you
This was selected as the best answer
Chris VillanuevaChris Villanueva
This worked, thank you very much!
Shubham Jadhav 70Shubham Jadhav 70
Hi , You can refer to article below for the same : https://salesforceidiot.blogspot.com/2023/05/update-custom-fonts-in-salesforce.html