Framework7 And Single Page Application: Preload All Pages

I'm using Framework7 to build a web application.

I know Framework7 provides routing APIs to navigate through the HTML pages.

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



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:

  1. Declare global or helper js file.
  2. after declare it, create method/methods inside it which it most be trigger when you visit route, and save the result in global variable (ex: aboutUsDataCache) which can access it in route.
  3. replace all ajax request routes action to method which created for it.
  4. add condition to check if aboutUsDataCache is empty or not, if not empty thats mean we trigger request and has data and we are in SPA, so that we dont to access method again.

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){
              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:

  1. This example usage WebPack, so that you see import and export some time..
  2. I remove promise from functions to make code example is clear.
  3. since you need to trigger all request at start, you need to call all methods in index route, so that when you go to any page like our example you will see data is cached and request will not trigger.

Good luck