Client-Side Dynamic Removal of [removed] Tags in <head>

后端 未结 5 2144
南笙
南笙 2021-01-31 10:37

Is it possible to remove script tags in the of an HTML document client-side and prior to execution of those tags?

On the server-side I am able

5条回答
  •  渐次进展
    2021-01-31 11:18

    No you can't

    I cannot find official documentation right now, but as I'm reading on High Performance Javascript from Nicholas Zakas, when the render engine founds a Tag script, it stops HTML rendering (so no other node is created), downloads the script and executes it. Then it continues rendering the HTML. That's why when you execute "document.write()" on a tag, the result is added JUST after the tag, then the rest of the page is rendered.

    (I don't know if I can insert a paragraph of the book here...)

    So it's not like rendering the page, then you remove the node and the script wont be executed, when the browser founds a tag you cannot do anything until this code is executed.

    We had a very similar problem at our product, we added a script tag to the DOM and we needed some code to be executed JUST before the new tag execution starts, after a week of research we had to find another solution.

    Sorry, but I hope you don't waste so much time as we did. Anyway I'll keep looking for browser specification.

提交回复
热议问题