+321 123 4567
info@test.com
  • Home
  • My Services
    • Web Design
    • Web Development
    • Technical Writing
  • Portfolio
  • My Thoughts
  • Free Tools
    • Photo Editor
    • Avatar Generator
    • Email Migration Tool
    • QR Code Generator
    • RSS to HTML Converter
    • Rich Text Editor
    • IP Address Geolocation
    • Base64 Image Encoder
    • NATO Translator
    • All Tools
  • Contact
Home
Webmasters
Fix CORS Policy Error: FontAwesome Icons Not Working With MaxCDN

Fix CORS Policy Error: FontAwesome Icons Not Working With MaxCDN

Wale Adekile
April 27, 2018

Serving your static files through a content delivery network (CDN) is one of the many ways to speed up a website. At the moment, I use MaxCDN and it has been great. Integrating the service with WordPress isn’t difficult so far you use a caching plugin like W3 Total Cache or WP Super Cache. However, if you display icons on your site using FontAwesome, things break and icons appear as squares.


font awesome appearing as little squares

In the image above, the search icon beside the input field appears as a weird little box. I’ve been having this issue over the last few months. Strangely, this happens only on Google Chrome and Opera. Everything appears to be fine when I checked the website on Safari and Firefox. I ignored it for a while, but I had to find a way to fix it since most of my visitors use Google Chrome.

Checking the browser console, the error was described as:

Redirect from ‘<resource CDN URL>’ to ‘<resource website URL>’ has been blocked by CORS policy: No ‘Access-Control-Allow-Origin’ header is present on the requested resource. Origin ‘<website>’ is therefore not allowed access.

Why this is happening

According to MaxCDN:

When using Webfonts via @font-face or other CSS3 methods, some browsers like Firefox and IE will refuse to embed the font when it’s coming from a 3rd party URL because it’s a security risk.

Fixing this is quite easy and there are actually two ways to go about it.


Modifying MaxCDN’s settings to allow Cross-Origin Resource Sharing

This was all I did to get this issue fixed.

1. Log in to your MaxCDN account and select your pull zone.

2. Select the Settings tab.

3. Under Edge Settings, enable Add CORS Header and save.

MaxCDN EDGE settings

4. Select the Manage Cache tab and Purge All Files.

purge maxcdn


5. If you use cache plugins like W3 Total Cache or WP Super Cache, be sure to purge everything. This also applies to Minify plugins like Fast velocity minify.

This should fix the problem and FontAwesome icons should start appearing normally.

font awesome search icon If this isn’t working, you might try the second fix.

Editing your .htaccess file

If the fix above doesn’t work for your, log in to your hosting control panel and put these codes into the .htaccess file:

[code]# ———————————————————————-
# CORS-enabled images (@crossorigin)
# ———————————————————————-
# Send CORS headers if browsers request them; enabled by default for images.
# developer.mozilla.org/en/CORS_Enabled_Image
# blog.chromium.org/2011/07/using-cross-domain-images-in-webgl-and.html
# hacks.mozilla.org/2011/11/using-cors-to-load-webgl-textures-from-cross-domain-images/
# wiki.mozilla.org/Security/Reviews/crossoriginAttribute
<IfModule mod_setenvif.c>
<IfModule mod_headers.c>
# mod_headers, y u no match by Content-Type?!
<FilesMatch "\.(gif|png|jpe?g|svg|svgz|ico|webp)$">
SetEnvIf Origin ":" IS_CORS
Header set Access-Control-Allow-Origin "*" env=IS_CORS
</FilesMatch>
</IfModule>
</IfModule>
# ———————————————————————-
# Webfont access
# ———————————————————————-
# Allow access from all domains for webfonts.
# Alternatively you could only whitelist your
# subdomains like "subdomain.example.com".
<IfModule mod_headers.c>
<FilesMatch "\.(ttf|ttc|otf|eot|woff|woff2|font.css|css|js)$">
Header set Access-Control-Allow-Origin "*"
</FilesMatch>
</IfModule>[/code]

Not that the code above only works for Apache servers. If you’re running an IIS, Nginx or a different kind of server, check this page.


Previous Post
PS4 vs PS4 Slim vs PS4 Pro: Which One is The Best to Buy?
Next Post
Why Your Smartphone Camera Takes Blurry Photos
Wale Adekile
Husband to the world's most beautiful woman and father to two awesome kids. A nerd, obviously; also, a technical business analyst, a web designer who preaches the gospel of WordPress, and a writer. You can check out my published books on Amazon.
web design
Webmasters

Attracting Visitors Through Web Presentation

12 years ago
ip address
Internet SecurityWebmasters

How to Create a Personal VPN (OpenVPN) on Your VPS

7 years ago

Recent Articles

wahl rapic clip hair clipper
Wahl Rapid Clip Hair Clipper Review: DIY Made Easy
BenQ LaptopBar Review: Luxury or Necessity?
yunmai easepro unboxed
Yunmai EasePro Massage Gun Review
g20
Teendow G20 Robot Vacuum and Mop Review
bathroom
Dear Men, Spraying All Over the Toilet Seat is Disgusting and Irresponsible
winx mediatrans
How to Transfer Photos from iPhone to Computer Without iTunes
google workspace
How to Migrate Emails From Google Workspace/G Suite to cPanel
synology diskstation ds920+
Synology DiskStation DS920+ Review
playstation 4
Why I haven’t Upgraded to the PlayStation 5 Yet
pain
Started Watching Anime as an Adult? You’re Not Alone

All contents on this blog are copyright protected and cannot be reproduced on other websites without permission.

Copyright © 2022 – NerdieDad | Home | Contact | About | Privacy Policy