I'm thinking of building a website using mustache.js to render the website and having PHP as the backend. The PHP will then mainly contain queries to the database and some SESSION checkings.
Previously I've used plain PHP to render the frontend but it gets way too messy.
An example of what I'm thinking:
HTML File
<html>
<head>
<script>
$.ajax{
url: "path/to/file.php",
...
success: function(response){
var template = $('#template').html();
var rendered = Mustache.render(template, response)
$('#template').html(rendered);
}
}
</script>
</head>
<body>
<p id="template">Your favourite website is {{website}}</p>
</body>
</html>
PHP File
<?php
function getWebsite($userid){
$mysqli = (...);
$stmt = $mysqli -> prepare("SELECT name FROM websites WHERE userId = ?");
$stmt -> bind_param("i", $userId);
$stmt -> execute();
...
...
echo json_encode($results);
}
?>
Is this a good structure or will it still get messy? Will it be slower?