make your most of the code in javascript
even if you are getting some array objects from php give it to javascript variable then put your logic in javascript, append prepend the html with javascript . if you can provide some snippet code from .phtml file which was late you think for disabling cache, it will be helpfull. i did same thing in my phtml file, where caching issue was very problematic.