Reputation: 7782
After having loaded all the scripts in a page, can I safely call $('script').detach();
to remove the scripts from the DOM?
Note: It is the equivalent of Array.from(document.getElementsByTagName("script")).forEach(script => script.remove())
Doing so would reduce the number of Node in the page and make certain queries faster (ex: $('*')
).
Are there any side effects of doing so? If not, why doesn't everyone use this trick?
Upvotes: 0
Views: 16
Reputation: 7169
you can, but in fact - if you use *
selector a lot - tag script not your major problem.
And if you have more than 3-7-10 scripts on your pages - that's the sign to check your page/coding pipeline
So the answer is - yes, you can
Extended answer - in normal situation it won't give you any pos
Upvotes: 1