Closes #49: otf and eot fonts shouldn't be processed by default with preload fonts#50
Conversation
There was a problem hiding this comment.
Pull Request Overview
This PR enhances font file detection by dynamically generating the regex for processing font file extensions based on configuration, thereby excluding otf and eot from the defaults.
- Replaces the static FONT_FILE_REGEX with an instance-specific regex using processed_extensions from the configuration.
- Updates the getNetworkLoadedFonts method to use the new instance-specific regex.
Comments suppressed due to low confidence (1)
src/BeaconPreloadFonts.js:8
- [nitpick] Consider adding tests to verify the dynamic regex generation behavior with different processed_extensions configurations.
const extensions = (Array.isArray(this.config.processed_extensions) && this.config.processed_extensions.length > 0 ? this.config.processed_extensions : ["woff", "woff2", "ttf"])
Coverage summary from CodacySee diff coverage on Codacy
Coverage variation details
Coverage variation is the difference between the coverage for the head and common ancestor commits of the pull request branch: Diff coverage details
Diff coverage is the percentage of lines that are covered by tests out of the coverable lines that the pull request added or modified: See your quality gate settings Change summary preferencesFootnotes
|
|
@jeawhanlee Done :) |
Description
Fixes #49
The list of font extensions processed will now be dynamically coming from WP Rocket filter rather than a static value.
Type of change
Detailed scenario
What was tested
The value is coming from the variable in the page. If we can't get it, then we have default values.
How to test
Please run with wp-media/wp-rocket#7318 to have the actual variable being added to the html
Technical description
Documentation
This pull request updates the
BeaconPreloadFontsclass to allow configurable font file extensions and improves the flexibility of font file detection. The most important changes include replacing the staticFONT_FILE_REGEXwith an instance-specific regex based on the configuration and updating font-loading logic to use the new regex.Updates to font file detection:
src/BeaconPreloadFonts.js: Replaced the staticFONT_FILE_REGEXwith an instance-specific regex (this.FONT_FILE_REGEX) that is dynamically generated based on theprocessed_extensionsconfiguration. If no configuration is provided, it defaults to["woff", "woff2", "ttf"]. This change ensures greater flexibility in specifying font file extensions.src/BeaconPreloadFonts.js: Updated thegetNetworkLoadedFontsmethod to use the instance-specificthis.FONT_FILE_REGEXinstead of the removed staticFONT_FILE_REGEX. This aligns the method with the new customizable regex logic.New dependencies
None
Risks
None
Mandatory Checklist
Code validation
Code style
Unticked items justification
No test for that