Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can Javascript modify the HTML stream rather than DOM tree?

I am aware that JavaScript can change the DOM tree during HTML parsing. But can it change the html stream (byte stream from network) during the parsing?

like image 745
JackWM Avatar asked May 10 '26 19:05

JackWM


1 Answers

The HTML stream is what contains the references to your JS so no, the HTML has already been at least partially processed before JS runs. What you could do though is create a separate HTML page without anything in the body and then have a script which fetches the original HTML via AJAX, screws with the response, and then injects it into the DOM. This is prone to all sorts of problems but really your only path for having client-side JS muck with server-provided HTML before adding to DOM.

like image 111
Robert Levy Avatar answered May 12 '26 07:05

Robert Levy