Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bootstrapping queries #2193

Open
ptbrowne opened this issue Nov 15, 2019 · 0 comments
Open

Bootstrapping queries #2193

ptbrowne opened this issue Nov 15, 2019 · 0 comments

Comments

@ptbrowne
Copy link
Contributor

ptbrowne commented Nov 15, 2019

Right now, before any data queries are made by an app, we have to

  • Load the page
  • Load the JS
  • Mount components
  • Components needing data will fire up queries

This leads to an important delay to show any data on the cozy.

To remove this delay, I think it would be interesting if the stack could know which queries does an app need before hand, execute the queries and serve the HTML with data that could be picked up by the application and inserted into cozy-client's store.

manifest.webapp

{
  initialQueries: {
    index: { // name of the page
      transactions: {
        type: 'io.cozy.bank.operations',
        selector: {
          ...a mango selector...
        }
      }
    }
  }
}

On cozy-client's instantiation, it could pick up the data (stored in a global JS variable for example like __BOOTSTRAP_DATA__) and populate its store.

This would potentially remove the need for any initial queries on page load.

Advantages

  • Simplicity for the app developer, declaring data needs in the manifest is simple
  • Declarativeness. The query being declared as data, it is easier to handle. The stack could create the right indexes before the app is launched, could warn the developer if there is something wrong with the query.

Inconvenients

  • If initial queries take a long time, the loading of the page is blocked (white page during loading).

Alternatives

Data loading JS bundle + UI JS bundle

An application could use bundling tools to serve two JS, a small one dedicated to data fetching. It would load very fast and fire up the queries. A bigger bundle containing the UI components and the rest of the app could be downloaded in parallel.

Advantages:

  • No work on the stack
  • JS assets download is not blocked by data fetching queries

Inconvenients:

  • Put bundling complexity on the app
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants