Closed Miraeld closed 1 week ago
Coverage variation | Diff coverage |
---|---|
Report missing for 4160df17680a0cb36febcb4aa55261d9e00ea9e4[^1] | :white_check_mark: 56.64% (target: 50.00%) |
Codacy stopped sending the deprecated coverage status on June 5th, 2024. Learn more [^1]: Codacy didn't receive coverage data for the commit, or there was an error processing the received data. Check your integration for errors and validate that your coverage setup is correct.
Coverage variation | Diff coverage |
---|---|
Report missing for 6fcdd7acfdf847716ba6810cc83330a9cddfc7be[^1] | :white_check_mark: 85.71% (target: 50.00%) |
Codacy stopped sending the deprecated coverage status on June 5th, 2024. Learn more [^1]: Codacy didn't receive coverage data for the commit, or there was an error processing the received data. Check your integration for errors and validate that your coverage setup is correct.
I tested that this works as expected.
Description
https://github.com/wp-media/wp-rocket/pull/7091 needs to be merged first. This PR is based on the current build of this PR. Only the last two commits are for this PR.
Fixes #7066 We are removing the
prefetch
andpreconnect
tag from the html if we are serving local hosted google fonts.Type of change
Detailed scenario
Media
tab of WPR settingsTechnical description
Documentation
This enhancement introduces a method to remove preconnect and prefetch links for Google Fonts from the HTML content. The purpose of this change is to optimize the loading process by eliminating unnecessary DNS prefetch and preconnect requests for Google Fonts.
How It Works
Method Introduction: A new private method remove_preconnect_and_prefetch is added to the Controller class.
HTML Content Check: The method first checks if the provided HTML content is empty. If it is, the original HTML is returned.
Filter Application: A filter
rocket_remove_font_pre_links
is applied to determine whether the preconnect and prefetch links should be removed. If the filter returns false, the original HTML is returned.Pattern Matching: A regular expression pattern is used to match
preconnect
andprefetch
links for Google Fonts.Tags Removal: The matched tags are removed from the HTML content using
preg_replace
.Return Modified HTML: The modified HTML content, without the
preconnect
andprefetch
links, is returned.New dependencies
None
Risks
None
Mandatory Checklist
Code validation
Code style