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

Optimize Head regex #2781

Open
wants to merge 3 commits into
base: dev
Choose a base branch
from

Conversation

MichaelWest22
Copy link
Contributor

@MichaelWest22 MichaelWest22 commented Aug 1, 2024

Description

Their was a change to add a regex tag utility function in #2024 and this combined three regex creations into a single function. Since then it seems the svg and title regex were simplified out with the htmx 2.0 re-write and we are now left with a redundant function that is only used to generate a single HEAD_TAG_REGEX which is only used once in makeFragment. So my proposed change here is to just simply remove this utility function and move the single use regex inline which should simplify readability and code minification.

Previous regex format was:

new RegExp(`<${tag}(\\s[^>]*>|>)([\\s\\S]*?)<\\/${tag}>`, global ? 'gim' : 'im')

And I'm simplified this to:

/<head(\s[^>]*)?>.*?<\/head>/is

Note [\s\S] is now .* because of the s option and m option is not needed here.

Corresponding issue:

Testing

Found the manual tests added with the #2024 change and was able to manually test this change worked fine with these manual tests after updating the test to link to the now external head-support extension.
Also tested with npm run test but found that this remove head feature in makeFragment has no coverage in these tests as breaking it caused no test failures. Because it is only used by head-support extension and not core htmx.
Manually ran the manual-tests folder in the head-support extension with the updated htmx changes as well and found no issues.

Checklist

  • I have read the contribution guidelines
  • I have targeted this PR against the correct branch (master for website changes, dev for
    source changes)
  • This is either a bugfix, a documentation update, or a new feature that has been explicitly
    approved via an issue
  • I ran the test suite locally (npm run test) and verified that it succeeded

@Telroshan
Copy link
Collaborator

Note: I'm labeling this as performance as it doesn't make any functional change, but contributes in decreasing the library's size before & after minification

@MichaelWest22 MichaelWest22 changed the title Head regex Optimize Head regex Aug 5, 2024
@alexpetros
Copy link
Collaborator

Sure, looks good

@alexpetros alexpetros added the ready for review Issues that are ready to be considered for merging label Aug 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
performance ready for review Issues that are ready to be considered for merging
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants