The only way to fire scripts for sure is to reload the page.
You are not misunderstanding anything about page compilation. As the browser renders html it encounters <script>
tags. These it executes in the order that it encounters them.
As you yourself say, it is possible to use javascript to remove script blocks. While this is extremely unusual to the point of me only having heard of it a couple of times before (and calling jQuery.fn.text()
definitely does not do that), that alone makes it impossible to reliably re-execute everything.
That being said, because we do not usually want code executing before the browser has finished loading all elements into the page therefore it is a common pattern to run all your code only in response to the document's onload event. That is what your code it is doing when it sets up $(document).ready(function(){...})
or $(function(){...})
(those are both identical). Since that code always run in response to the document's loaded event you can always retrigger it with $(document).ready()
or $(document).trigger('ready')
However, test this out thoroughly since lots of libraries assume the event occurs only once.