mirror of
https://github.com/bigskysoftware/htmx.git
synced 2025-09-26 20:40:41 +00:00
Optimize Head regex (#2781)
* remove shared tag regex utility function that is no longer really needed * fix head-support manual test to point to externally hosted extension * minimize regex
This commit is contained in:
parent
b98e4f2b12
commit
5b550e5c49
14
src/htmx.js
14
src/htmx.js
@ -337,22 +337,10 @@ var htmx = (function() {
|
||||
return '[hx-' + verb + '], [data-hx-' + verb + ']'
|
||||
}).join(', ')
|
||||
|
||||
const HEAD_TAG_REGEX = makeTagRegEx('head')
|
||||
|
||||
//= ===================================================================
|
||||
// Utilities
|
||||
//= ===================================================================
|
||||
|
||||
/**
|
||||
* @param {string} tag
|
||||
* @param {boolean} global
|
||||
* @returns {RegExp}
|
||||
*/
|
||||
function makeTagRegEx(tag, global = false) {
|
||||
return new RegExp(`<${tag}(\\s[^>]*>|>)([\\s\\S]*?)<\\/${tag}>`,
|
||||
global ? 'gim' : 'im')
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses an interval string consistent with the way htmx does. Useful for plugins that have timing-related attributes.
|
||||
*
|
||||
@ -595,7 +583,7 @@ var htmx = (function() {
|
||||
*/
|
||||
function makeFragment(response) {
|
||||
// strip head tag to determine shape of response we are dealing with
|
||||
const responseWithNoHead = response.replace(HEAD_TAG_REGEX, '')
|
||||
const responseWithNoHead = response.replace(/<head(\s[^>]*)?>.*?<\/head>/is, '')
|
||||
const startTag = getStartTag(responseWithNoHead)
|
||||
/** @type DocumentFragmentWithTitle */
|
||||
let fragment
|
||||
|
@ -19,7 +19,7 @@
|
||||
</style>
|
||||
|
||||
<script src="../../../src/htmx.js" hx-preserve="true"></script>
|
||||
<script src="../../../src/ext/head-support.js" hx-preserve="true"></script>
|
||||
<script src="https://unpkg.com/htmx-ext-head-support@2.0.0/head-support.js" hx-preserve="true"></script>
|
||||
</head>
|
||||
<body hx-ext="head-support" hx-boost="true">
|
||||
<header hx-push-url="false" hx-target="main" hx-swap="innerHTML">
|
||||
@ -38,4 +38,4 @@
|
||||
</ul>
|
||||
</main>
|
||||
</body>
|
||||
</html>
|
||||
</html>
|
||||
|
Loading…
x
Reference in New Issue
Block a user