Skip to content

Commit 0572cbd

Browse files
committed
More cleanup
1 parent d3434b2 commit 0572cbd

File tree

1 file changed

+20
-13
lines changed

1 file changed

+20
-13
lines changed

jquery.pjax.js

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -643,23 +643,30 @@ function extractContainer(data, xhr, options) {
643643
return obj
644644
}
645645

646-
// Download and execute script tags once.
646+
// Load an execute scripts using standard script request.
647647
//
648-
// scripts - Array of script Elements
648+
// Avoids jQuery's traditional $.getScript which does a XHR request and
649+
// globalEval.
650+
//
651+
// scripts - jQuery object of script Elements
649652
//
650653
// Returns nothing.
651654
function executeScriptTags(scripts) {
652-
scripts.each(function(_, script) {
653-
var $script = $(script)
654-
var src = $script.attr('src')
655-
if ($('script[src="' + src + '"]').length) return
656-
657-
var target = document.head || context.get(0)
658-
var tag = document.createElement('script')
659-
tag.type = $script.attr('type') || "text/javascript"
660-
tag.async = false
661-
tag.src = src
662-
target.appendChild(tag)
655+
if (!scripts) return
656+
657+
var existingScripts = $('script[src]')
658+
659+
scripts.each(function() {
660+
var src = this.src
661+
var matchedScripts = existingScripts.filter(function() {
662+
return this.src === src
663+
})
664+
if (matchedScripts.length) return
665+
666+
var script = document.createElement('script')
667+
script.type = $(this).attr('type')
668+
script.src = $(this).attr('src')
669+
document.head.appendChild(script)
663670
})
664671
}
665672

0 commit comments

Comments
 (0)