This article will summarize how to load Font Awesome using plain or vanilla JavaScript. If you’re like me, you’re not using the WYSIWYG editor for A/B testing. You rather write your own clean plain JavaScript code.

This is what you would like to add as a script:

(function() {
‘use strict’;

// Insert FontAwesome
var fontAwesome = document.createElement(“script”);
fontAwesome.src = “https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.1.0/css/all.min.css”;
document.getElementsByTagName(“head”)[0].appendChild(fontAwesome);

})();

Code explained

First: You’ll create an element. This is the script that will be added to the head at the end of the JavaScript.

Second: Add the Font Awesome CDN link. The link that I’ve added can be used to find the most recent version of the Font Awesome CDN.

Third: Add the script to the head of the website.

Now you’re able to use Font Awesome within your A/B test. This worked with Google Optimize.