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 #7066: 3.18 - Preconnect and prefetch removal #7101

Conversation

Miraeld
Copy link
Contributor

@Miraeld Miraeld commented Nov 13, 2024

Description

#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 and preconnect tag from the html if we are serving local hosted google fonts.

Type of change

  • Enhancement (non-breaking change which improves an existing functionality).

Detailed scenario

  1. Enable the Host Local Font option under the Media tab of WPR settings
  2. Load a page with google fonts and prefetch/preconnect tags
  3. Check the HTML, both of these tags should be removed.

Technical 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 and prefetch 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 and prefetch links, is returned.

New dependencies

None

Risks

None

Mandatory Checklist

Code validation

  • I validated all the Acceptance Criteria. If possible, provide screenshots or videos.
  • I triggered all changed lines of code at least once without new errors/warnings/notices.
  • I implemented built-in tests to cover the new/changed code.

Code style

  • I wrote a self-explanatory code about what it does.
  • I protected entry points against unexpected inputs.
  • I did not introduce unnecessary complexity.
  • Output messages (errors, notices, logs) are explicit enough for users to understand the issue and are actionnable.

@Miraeld Miraeld requested a review from a team November 13, 2024 03:40
@Miraeld Miraeld self-assigned this Nov 13, 2024
@Miraeld Miraeld added the type: enhancement Improvements that slightly enhance existing functionality and are fast to implement label Nov 13, 2024
@Miraeld Miraeld changed the base branch from develop to feature/host-google-fonts November 13, 2024 03:41
Copy link

Coverage summary from Codacy

See diff coverage on Codacy

Coverage variation Diff coverage
Report missing for 4160df11 56.64% (target: 50.00%)
Coverage variation details
Coverable lines Covered lines Coverage
Common ancestor commit (4160df1) Report Missing Report Missing Report Missing
Head commit (a417d68) 38239 16768 43.85%

Coverage variation is the difference between the coverage for the head and common ancestor commits of the pull request branch: <coverage of head commit> - <coverage of common ancestor commit>

Diff coverage details
Coverable lines Covered lines Diff coverage
Pull request (#7101) 113 64 56.64%

Diff coverage is the percentage of lines that are covered by tests out of the coverable lines that the pull request added or modified: <covered lines added or modified>/<coverable lines added or modified> * 100%

See your quality gate settings    Change summary preferences

Codacy stopped sending the deprecated coverage status on June 5th, 2024. Learn more

Footnotes

  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.

Copy link

codacy-production bot commented Nov 13, 2024

Coverage summary from Codacy

See diff coverage on Codacy

Coverage variation Diff coverage
Report missing for 6fcdd7a1 85.71% (target: 50.00%)
Coverage variation details
Coverable lines Covered lines Coverage
Common ancestor commit (6fcdd7a) Report Missing Report Missing Report Missing
Head commit (9e97dbb) 38237 16767 43.85%

Coverage variation is the difference between the coverage for the head and common ancestor commits of the pull request branch: <coverage of head commit> - <coverage of common ancestor commit>

Diff coverage details
Coverable lines Covered lines Diff coverage
Pull request (#7101) 7 6 85.71%

Diff coverage is the percentage of lines that are covered by tests out of the coverable lines that the pull request added or modified: <covered lines added or modified>/<coverable lines added or modified> * 100%

See your quality gate settings    Change summary preferences

Codacy stopped sending the deprecated coverage status on June 5th, 2024. Learn more

Footnotes

  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.

@Miraeld Miraeld changed the base branch from feature/host-google-fonts to feature/7063-google-font-front-end November 14, 2024 01:52
@Miraeld Miraeld changed the base branch from feature/7063-google-font-front-end to feature/host-google-fonts November 14, 2024 07:57
@jeawhanlee
Copy link
Contributor

I tested that this works as expected.

@jeawhanlee jeawhanlee merged commit a6e21f5 into feature/host-google-fonts Nov 15, 2024
11 of 12 checks passed
@jeawhanlee jeawhanlee deleted the enhancement/7066-remove-preconnect-prefetch branch November 15, 2024 08:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: enhancement Improvements that slightly enhance existing functionality and are fast to implement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3.18 - Preconnect and prefetch removal
2 participants