Common Amazon Cloud Front and Magento 2 Issues and How to Solve Them

CloudFront on Magento 2 is undoubtedly a performance booster, as content delivery networks (CDN) like CloudFront, Cloudflare, MaxDCN, etc. are known for reducing server latency. Thus improving the website performance. Since CloudFront from Amazon is one of the top CDN services available on the market, many Magento owners prefer CloudFront over others.

Configuring CloudFront for Magento 2 is not a difficult job. With that said, there could be some common issues that delay the installation or make it incomplete.

1. Access-Control-Allow-Origin (CORS) Issue

CORS has been a global standard for accessing web files and content that are on a different domain. It’s a vital security protocol set up by most web browsers. The core idea of CORS is to prevent JS or CSS files from sending requests from different domains.

The problem can easily be solved by adding a rule to the .htaccess file.

Header adds Access-Control-Allow-Origin “*.”

2. HTTP/2 Compatibility 

HTTP/2 is a significant upgrade to the HTTP network protocol. The new protocol was introduced in 2015, and as of 2019, only 30% of the global websites switched to HTTP/2. While HTTP/2 certainly is an undoubted bonus in terms of performance, it can still create some issues for users – especially to those who use old and outdated browsers.

One of the common HTTP/2 compatibility issues is invalid response line returned from the server. It can be solved by adding a few rules to curl.php.

3. CloudFront and Magento 2 Google Font Blocking Issue

The problem is also seen with other CDN providers, not just CloudFront. The font-blocking issue again relates to the first problem we discussed earlier, which is a CORS issue. It can be solved by making a few changes to the core files.

Step 1: Specify file type in Apache virtual host file to whitelist the fonts.

Step 2: Write a rule in .htaccess to override access control header.

If the above two didn’t work, perhaps, changing Behavior settings in CloudFront could help. Turning on ‘Query String Forwarding and Caching’ could do the trick.

Professionals at Exinent can help set up Amazon CloudFront on Magento 2. Reach out to us if you need these problems fixed or supercharge it for better security, performance, and conversions.