Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closes #40: 3.19 Preload fonts beacon processing part #42

Merged
Show file tree
Hide file tree
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
19 changes: 16 additions & 3 deletions src/BeaconManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import BeaconLcp from "./BeaconLcp.js";
import BeaconLrc from "./BeaconLrc.js";
import BeaconPreloadFonts from "./BeaconPreloadFonts.js";
import BeaconUtils from "./Utils.js";
import Logger from "./Logger.js";

Expand All @@ -10,6 +11,7 @@ class BeaconManager {
this.config = config;
this.lcpBeacon = null;
this.lrcBeacon = null;
this.preloadFontsBeacon = null;
this.infiniteLoopId = null;
this.errorCode = '';
this.logger = new Logger(this.config.debug);
Expand All @@ -34,13 +36,16 @@ class BeaconManager {

const isGeneratedBefore = await this._getGeneratedBefore();

// OCI / LCP / ATF
// OCI / LCP / ATF / PRELOAD FONTS
const shouldGenerateLcp = (
this.config.status.atf && (isGeneratedBefore === false || isGeneratedBefore.lcp === false)
);
const shouldGeneratelrc = (
this.config.status.lrc && (isGeneratedBefore === false || isGeneratedBefore.lrc === false)
);
const shouldGeneratePreloadFonts = (
this.config.status.preload_fonts && (isGeneratedBefore === false || isGeneratedBefore.preload_fonts === false)
);
if (shouldGenerateLcp) {
this.lcpBeacon = new BeaconLcp(this.config, this.logger);
await this.lcpBeacon.run();
Expand All @@ -55,7 +60,14 @@ class BeaconManager {
this.logger.logMessage('Not running BeaconLrc because data is already available or feature is disabled');
}

if (shouldGenerateLcp || shouldGeneratelrc) {
if (shouldGeneratePreloadFonts) {
this.preloadFontsBeacon = new BeaconPreloadFonts(this.config, this.logger);
await this.preloadFontsBeacon.run();
} else {
this.logger.logMessage('Not running BeaconPreloadFonts because data is already available or feature is disabled');
}

if (shouldGenerateLcp || shouldGeneratelrc || shouldGeneratePreloadFonts) {
this._saveFinalResultIntoDB();
} else {
this.logger.logMessage("Not saving results into DB as no beacon features ran.");
Expand Down Expand Up @@ -101,7 +113,8 @@ class BeaconManager {
_saveFinalResultIntoDB() {
const results = {
lcp: this.lcpBeacon ? this.lcpBeacon.getResults() : null,
lrc: this.lrcBeacon ? this.lrcBeacon.getResults() : null
lrc: this.lrcBeacon ? this.lrcBeacon.getResults() : null,
preload_fonts: this.preloadFontsBeacon ? this.preloadFontsBeacon.getResults() : null
};

const data = new FormData();
Expand Down
Loading