Giter VIP home page Giter VIP logo

Comments (4)

micheleriva avatar micheleriva commented on May 25, 2024

It's doing a full refresh 'cause you're using getInitialProps in your _app.js file right?

from krabs.

28development avatar 28development commented on May 25, 2024

Yes.


App.getInitialProps = async ({ Component, ctx }) => {
  const tenant = ctx?.req?.tenant?.name;
  let pageProps = {};

  if (Component.getInitialProps) {
    pageProps = await Component.getInitialProps(ctx);
  }

  return {
    pageProps: {
      ...pageProps,
      tenant,
    },
  };
};

export default App;

from krabs.

28development avatar 28development commented on May 25, 2024

Using getServerSidePropsaswell as getStaticProps has the same effect.

export async function getStaticProps({ Component, ctx = null }) {
  const tenant = ctx?.req?.tenant?.name;
  let pageProps = {};

  if (Component.getStaticProps) {
    pageProps = await Component.getStaticProps(ctx);
  }

  return {
    pageProps: {
      ...pageProps,
      tenant,
    },
  };
}

Could you provide an example on how to solve this?

from krabs.

micheleriva avatar micheleriva commented on May 25, 2024

By using getInitialProps in your _app.js file, you require a full SSR for each page in your application. As for now, there's no way to avoid this behavior, but I have a suggestion: use a CDN such as Akamai or Cloudflare for caching your pages after the first render, and use their APIs for invalidating the cache manually or time-based (just like an "enhanced" ISR).

If you feel like wrapping your application behind a CDN is a bit too much, maybe Krabs it's not 100% needed 🙂 it is supposed to work on large-scale projects where a good caching layer is required anyway!

PS. I'm currently running Krabs in production on a two-domain application, and even if I SSR every single page, its performances (cache apart) are outstanding, and that's because Next.js is really well made.

from krabs.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.