Given a one-html-multiple-pages app, in each of my pages I plan JS inject long html codes and animations which can be heavy. HTML code such :
<div data-role="page" id="page11">
...
</div>
<div data-role="page" id="page12">
<h2 id="anchor12">Title: Page 12</h2>
<script>myScript12() // inject complex content to #anchor12</script>
</div>
1. When does my myScript12()
is fired ? (When I open the .html file or when I click and open the #page12 ?
2. What happen to the JS generated content when I leave #page12 for an other page ?
Edit: I don't want to load all my 20 heavy pages on .html load.
Solution: +1 for the detailed explanation by Gajotres (JQM: document ready vs page events), below is my current solution. To run the js ONLY when the given data-role="page" is displayed...
Use the following JQM HTML/JS:
<div data-role="page" id="page12">
<h2 id="anchor12">Title: Page 12</h2>
<script>
$('#page12').on('pageinit') { //only run when page is displayed
myScript12() // inject complex content to #anchor12
});</script>
</div>