Posted on 06/05/2017 11:49:33
We typically do 3) - something else ;-) Here's what we do:
1. We've created a super simple module called the TenmplateRenderer. All it does is take a template as part of its config screen that it renders when it's executed.
2. We then use that module with CSHTML templates to render specific (AJAX) functionality
3. We set up pages in the backend (in a sub folder structure like System/Ajax for example) for specific purposes. These pages can be set up to return JSON (or whatever you want) and execute the requested template using whatever server side logic is needed. For module specific scenarios (like a mini cart that is loaded on demand), we use the module itself and its templates, bypassing the custom TemplateRenderer module.
Does this help? Let me know if you need more examples on any of these steps.
Cheers,
Imar