Skip to main content
Active Contributor I
Jun 26, 2024 2:56 PM UTC
Solved

Custom Fonts // CORS works

Hi there,

 

I’ve seen there are a ton of “can’t add my custom font” posts. Sorry to post another one.

It looks like the solution for pretty much all of them was related to CORS and setting an access control policy.

So I have set that up and verified it works. 

 

When I curl my font with Klaviyo as Origin I get a success response and can download the font-file.

curl -v --request GET 'https://mydomain.com/path/to/my/font.woff2' --header 'ORIGIN: https://klaviyo.com'



> Host: mydomain.com
> User-Agent: curl/8.6.0
> Accept: */*
> ORIGIN: https://klaviyo.com
>
{ [5 bytes data]
* TLSv1.3 (IN), TLS handshake, Newsession Ticket (4):
{ [281 bytes data]
* TLSv1.3 (IN), TLS handshake, Newsession Ticket (4):
{ [281 bytes data]
* old SSL session ID is stale, removing
{ [5 bytes data]
< HTTP/1.1 200 OK
< Date: Wed, 26 Jun 2024 14:33:30 GMT
< Server: Apache/2.4.59 (Debian)
< Last-Modified: Mon, 25 Mar 2024 15:54:20 GMT
< ETag: "16074-6147e2fc5fcb6"
< Accept-Ranges: bytes
< Content-Length: 90228
< Content-Type: font/woff2

 

On Klaviyo I still get the error “One or more font files could not be accessed.”

 

Running Shopware 6 on an Apache2 webserver. This is my access control policy in my .htaccess in public root directory:

<FilesMatch "\.(ttf|otf|eot|woff|woff2)$">
<IfModule mod_headers.c>
Header set Access-Control-Allow-Origin "*"
</IfModule>
</FilesMatch>

 

Any suggestions?
More insight on the error would also be helpful if anyone from Kalviyo Staff is able to provide it.

 

Thanks!

Nico

    This topic has been closed for replies.
    Kim Strauch
    Klaviyo Employee
    Jun 28, 2024 2:06 PM UTC

    Hey @CP-Nico, I believe your CORS headers setup is incorrect. You get a 200 in CURL but this is not indicative of how a browser would behave. 

    The easiest way to verify that you have a CORS issue is to call “fetch(URL)” in the browser dev tools. I've posted a screenshot to demonstrate that I am seeing a CORS error in trying to load this font URL from a browser.

    It appears your server is not setting the  Access-Control-Allow-Origin response header properly, so the problem must lie somewhere in your Apache/htaccess setup. 

     

    9 replies

    Partner
    Jun 27, 2024 9:24 AM UTC

    Hello @CP-Nico Could you please share the screenshot of the error?

    https://theforms.pro
    CP-NicoAuthor
    Active Contributor I
    Jun 27, 2024 9:26 AM UTC

    Hey @Maxbuzz, here you go:

     

    Partner
    Jun 27, 2024 10:15 AM UTC

    Hello @CP-Nico  if possible could you please share the Font URL here or in messages?

    https://theforms.pro
    CP-NicoAuthor
    Active Contributor I
    Jun 27, 2024 12:32 PM UTC
    Kim Strauch
    Klaviyo Employee
    Klaviyo Employee
    Jun 28, 2024 2:06 PM UTC

    Hey @CP-Nico, I believe your CORS headers setup is incorrect. You get a 200 in CURL but this is not indicative of how a browser would behave. 

    The easiest way to verify that you have a CORS issue is to call “fetch(URL)” in the browser dev tools. I've posted a screenshot to demonstrate that I am seeing a CORS error in trying to load this font URL from a browser.

    It appears your server is not setting the  Access-Control-Allow-Origin response header properly, so the problem must lie somewhere in your Apache/htaccess setup. 

     

    Partner
    Jun 28, 2024 2:23 PM UTC

    Hello @CP-Nico If you are not able to make it work with .htaccess then I would suggest to create a s3 bucket on AWS tier and enable CROS there. It is less technical and easy to work with.

    https://theforms.pro
    CP-NicoAuthor
    Active Contributor I
    Jun 29, 2024 9:31 AM UTC

    Cheers guys @Kim Strauch @Maxbuzz. I’ll investigate tomorrow an update here once (hopefully) successful.

    CP-NicoAuthor
    Active Contributor I
    Jun 30, 2024 12:29 PM UTC

    So turns out I hadn’t enabled the apache mod headers for my .htaccess directive to actually do anything. Rookie error. Works now.

    Thanks again @Maxbuzz and @Kim Strauch !

    Kim Strauch
    Klaviyo Employee
    Klaviyo Employee
    Jul 1, 2024 1:48 PM UTC

    @CP-Nico glad you got that sorted out!