opral / inlang.com

This repo is for collecting issues around inlang.com (https://github.com/opral/monorepo/tree/main/inlang/source-code/website)
1 stars 0 forks source link

Loading the landingpage is slow #83

Closed NilsJacobsen closed 4 months ago

NilsJacobsen commented 4 months ago
NilsJacobsen commented 4 months ago

"The data() hook is only meant for fetching the initial data of a page (in technical words: the SSR data). For other use cases see the sections below API routes and RPC." -> https://vike.dev/data-fetching

The data hook is meant for initial page load. We should probably switch to rpc for this again.

NilsJacobsen commented 4 months ago

Can we cache from the data hook in vike? Gonna check.

samuelstroschein commented 4 months ago

No, rpc has nothing to do with this. You are running code on the server already, you don't need rpc. (RPC means you query client side to the server for things that can be queried on the client. You are already running the query on the server.) You need to cache the data. You have two options:

  1. Cache with a variable on top of the module [assuming that the module stays hot e.g. the state is not gargabe collected]
let cachedProjectCount = undefined
let cacheLastSet = undefined

export function data() {
  if (cacheLastSet is newer than 24 hours){
    return cachedProjectCount
  } else {
    cachedProjectCount = queryPostHog()
    cacheLastSet = now()
  }
}
  1. Use SSG for the main page/entire website https://vike.dev/pre-rendering
NilsJacobsen commented 4 months ago

Well with rpc you could run it from the client, to let it not influence the navigation times. But well I like your first proposal. Let me try integrate it.

samuelstroschein commented 4 months ago

Well with rpc you could run it from the client, to let it not influence the navigation times

Yeah but now you increase the loading time by shipping more JS to the client for a query you will execute on the server anyways

NilsJacobsen commented 4 months ago

True but I felt like the js is not causing nearly as much time then the api call. But yeah let's try the variable solution.