Client-Side Dynamic Removal of <script> Tags in <head>

JesusLives

New Member
Is it possible to remove script tags in the \[code\]<head>\[/code\] of an HTML document client-side and prior to execution of those tags?I am able to insert a \[code\]<script>\[/code\] above all other \[code\]<script>\[/code\] tags in the \[code\]<head>\[/code\], except one, and I would like to be able to remove all subsequent scripts. I have tried\[code\](function (c,h) { var i, s = h.getElementsByTagName('script'); c.log("Num scripts: " + s.length); for(i = 2; i < s.length; i++) { h.removeChild(s); }})(console, document.head);\[/code\]However, the logged number of scripts is coming out to only 1, which means that it's not even counting the one which is executing (or perhaps that's the only one being counted?). If I run this same script in the \[code\]<body>\[/code\] it executes fine, but by that point all the other scripts are loaded.If you want more context, this is part of an attempt to consolidate scripts where no option for server-side aggregation is available. The content is mostly static, so there is very little concern about manually aggregating the JavaScript and serving it from a different location.
 
Back
Top