Reputation: 11648
I'm using Framework7 to build a web application.
I know Framework7 provides routing APIs to navigate through the HTML pages.
https://framework7.io/docs/view.html#router-api-methods-properties
As far as I know the pages are loaded on the fly via AJAX requests. Is it possible to preload all of them and not having any AJAX request after that? I'd like to build a single page application (SPA) in which all the data (HTML pages, CSS and JavaScript code) is loaded at startup
Upvotes: 1
Views: 728
Reputation: 3560
I think theirs no direct solution to do it like your question, since every route will trigger requests when you visit it, but you can try to fix your issue by doing this trick:
Example from real project: I have main-config.js which is load before routes and has this code:
module.exports.tmpAppCache = {
fullCadaverList: false,
fullImagesList: false,
fullVideosList: false,
fullPdfList: false,
};
and I have ajax-helper.js file which its loaded before routes too and have methods like this:
export function getFullPdfList() {
// Your ajax request here
}
in routes has this code:
{
path: '/pdf/',
async: function (routeTo, routeFrom, resolve, reject) {
if(globalObject.tmpAppCache.fullPdfList !== false){
resolve(
{
component: pdfPage,
},
{
context: {
data: globalObject.tmpAppCache.fullPdfList
}
}
);
}else{ getFullPdfList()
}
},
},
This example from real project, I try to remove all unwanted code to be something clear so that theres some note:
Good luck
Upvotes: 1