I’m starting with Framework7 after reading the docs to my best capacities, and searching for hours to try to understand this topic about routes/templates.
Let’s take the following example, from the “official starter templates” page
{
path: '/page-loader-template7/:userId',
async: function (routeTo, routeFrom, resolve, reject) {
app.request.post('http://someurl/userdata.php',
{
user_id: routeTo.params.userId
},
function (data) {
resolve(
{
templateUrl: './pages/page-loader-template7.html'
},
{
context: {
user: data,
}
});
},
null,
'json'
);
}
},
So far so good. That works. But, here, it says:
Template7 is fast and you can make it even faster in your apps. The slowest part (but still very fast in T7) in compilation/rendering process is the compilation from string to pure JS function when you do Template7.compile(). So don’t compile the same templates multiple times, one time will be enough:
And here, it says (on the description of the templateUrl route property):
Load page content from url via Ajax, and compile it using Template7
So, i came up with this:
{
path: '/page-loader-template7/:userId',
async: function (routeTo, routeFrom, resolve, reject) {
app.request.post('http://someurl/userdata.php',
{
user_id: routeTo.params.userId
},
function (data) {
resolve( {
template: compiled_template(data)
});
},
null,
'json'
);
}
},
That also works, but it requires that the template be defined in the same file as the routes, which is kind of unscalable and awkward.
So, questions:
- Using the first, suggested, way, is the template really compiled every time we navigate to the route, making it slow, as they recommend NOT to do?
- Using the second, own, way, is there some way i can put the template (even component, eventually) in a separate file?
Thanks!