skip to Main Content

I have a question, suppose there are two scenarios before login and after login:

Before login
Website will be SEO with next js or some other way. And has few pages like blog, blog details, about, contact, and products etc.

After login
Normal feature like post, post details with CRA(Create React App) setup.

My question is how do we setup the project with before login in SSR and after login. I don’t want SSR after login because there are lots of load on server for each features and functionality.
Is there any solution?

I have few article on isomorphic like https://hackernoon.com/get-an-isomorphic-web-app-up-and-running-in-5-minutes-72da028c15dd

example starter kit project: https://github.com/xiaoyunyang/isomorphic-router-demo

Can we create both SSR and Create react app within one project setup?

2

Answers


  1. If you’re using an express server you can use ssr-for-bots middleware to apply ssr to certain routes only.

    const ssrForBots = require("ssr-for-bots");
    
    const defaultOptions = {
      prerender: [], // Array containing the user-agents that will trigger the ssr service | uses Regex
      exclude: ["/routesAfterLogin/"], // Array containing paths and/or extentions that will be excluded from being prerendered by the ssr service | uses Regex
      useCache: true, // Variable that determins if we will use page caching or not
      cacheRefreshRate: 86400, // Seconds of which the cache will be kept alive, pass 0 or negative value for infinite lifespan default 24 hours
    };
    
    app.use(ssrForBots(defaultOptions)); 
    

    That way the paths before login will be SSR, and paths after login (let’s say they all start with /app) will be excluded

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search