Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions src/BeaconPreloadFonts.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,15 @@ class BeaconPreloadFonts {
this.config = config;
this.logger = logger;
this.aboveTheFoldFonts = [];
// Use processed_extensions from config if set, otherwise default to ["woff", "woff2", "ttf"].
const extensions = (Array.isArray(this.config.processed_extensions) && this.config.processed_extensions.length > 0
? this.config.processed_extensions
: ["woff", "woff2", "ttf"])
.map(ext => ext.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'))
.join('|');
this.FONT_FILE_REGEX = new RegExp(`\\.(${extensions})(\\?.*)?$`, 'i');
}

static FONT_FILE_REGEX = /\.(woff2?|ttf|otf|eot)(\?.*)?$/i;

/**
* Checks if a given font family is a system font.
*
Expand Down Expand Up @@ -75,8 +80,8 @@ class BeaconPreloadFonts {
getNetworkLoadedFonts() {
return new Map(
window.performance
.getEntriesByType('resource')
.filter((resource) => BeaconPreloadFonts.FONT_FILE_REGEX.test(resource.name))
.getEntriesByType("resource")
.filter((resource) => this.FONT_FILE_REGEX.test(resource.name))
.map((resource) => [this.cleanUrl(resource.name), resource.name])
);
}
Expand Down