I found that starting a document with the <script> tag erased whatever I put in there up to any text that was on the page.
I have found that putting some text at the beginning usually works for not deleting the scripts. Place the script & style sheets at the end or middle of the document