Skip to content

Commit 3a32250

Browse files
kakserpommislav
authored andcommitted
Avoid testing the same regular expression twice
Closes #314
1 parent fa3227a commit 3a32250

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

jquery.pjax.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -652,14 +652,14 @@ function parseHTML(html) {
652652
//
653653
// Returns an Object with url, title, and contents keys.
654654
function extractContainer(data, xhr, options) {
655-
var obj = {}
655+
var obj = {}, fullDocument = /<html/i.test(data)
656656

657657
// Prefer X-PJAX-URL header if it was set, otherwise fallback to
658658
// using the original requested url.
659659
obj.url = stripPjaxParam(xhr.getResponseHeader('X-PJAX-URL') || options.requestUrl)
660660

661661
// Attempt to parse response html into elements
662-
if (/<html/i.test(data)) {
662+
if (fullDocument) {
663663
var $head = $(parseHTML(data.match(/<head[^>]*>([\s\S.]*)<\/head>/i)[0]))
664664
var $body = $(parseHTML(data.match(/<body[^>]*>([\s\S.]*)<\/body>/i)[0]))
665665
} else {
@@ -692,7 +692,7 @@ function extractContainer(data, xhr, options) {
692692
obj.title = $fragment.attr('title') || $fragment.data('title')
693693
}
694694

695-
} else if (!/<html/i.test(data)) {
695+
} else if (!fullDocument) {
696696
obj.contents = $body
697697
}
698698

0 commit comments

Comments
 (0)