如果脚本标签重复,有没有办法使用 liquid 进行验证?

Is there a way to verify using liquid, if script tag is duplicated?

我想使用流动语言检查页面中是否有脚本被调用两次或更多次。 例如:

<script src="myscripts.js"></script>
<script src="myscripts.js"></script>

是否可以使用液体或者我应该使用 javascript 来验证?

我不确定 liquid,但如果你想走 JS 路线,这可能行得通:

//locate all `<script>` tags and save the elements into an array
var scriptTags = [];
document.querySelectorAll('script').forEach(function(tag) {
  scriptTags.push(tag)
});

//Put just the URLs of the script tags into an array
var scriptUrls = scriptTags.map(function(tag) {
  return tag.src;
});

//Get a list of any URL that appears more than once
var duplicateUrls = scriptUrls.filter(function(url, i) {
  return scriptUrls.indexOf(url) != i;
});

console.log(duplicateUrls);
<script src="dupe.js"></script>
<script src="other1.js"></script>
<script src="dupe.js"></script>
<script src="other2.js"></script>
<script src="other3.js"></script>