Timeout due to parsing Nuxt Content documents every cold start in Vercel server

257 Views Asked by At

I've a web built with Nuxt 2 deployed in Vercel where I'm using the @nuxt/content module for rendering some articles. It's using SSR and target: server, and everytime the server hibernates due to lack of activity, the first load takes +10 seconds or directly returns a timeout.

It's caused because when the server does the cold start, it is parsing the documents again reaching the time limit. I'm not sure why is this happening and how can I fix it. I guess moving to ssr: false can maybe help but I'm afraid my SEO can be affected. I believe a better solution should exist just to avoid re-parsing the documents everytime it does a cold start.

Nuxt version: 2.15.7
@nuxt/content version: 1.14.0
@nuxtjs/vercel-builder version: 0.22.1
Running on Node 16

Parsing documents at cold start

nuxt.config.js

export default {
  ssr: true,

  target: "server",

  plugins: [
    "@/plugins/articleManager.ts",
    "@/plugins/leaflet.client.js",
    "@/plugins/device.server.js",
  ],

  components: true,

  buildModules: [
    "@nuxt/typescript-build",
    "@nuxtjs/vuetify",
    "vue-ssr-carousel/nuxt",
  ],

  modules: [
    "@nuxtjs/pwa",
    "@nuxt/content",
    "@nuxtjs/sitemap",
    "@nuxtjs/robots",
    "@nuxt/image",
  ],

  content: {
    fullTextSearchFields: ["title", "description"],
  },

  build: {
    build: {
      extend(config, { isClient }) {
        if (isClient) {
          config.devtool = "source-map";
        }
      },
    },
  },

  srcDir: "src/",
};

vercel.json

{
  "version": 2,
  "builds": [
    {
      "src": "package.json",
      "use": "@vercel/node"
    },
    {
      "src": "nuxt.config.js",
      "use": "@nuxtjs/vercel-builder",
      "config": {
        "serverFiles": [
          ".nuxt/content/**",
          "src/content/**",
          "server/**",
          ".nuxt/dist/sitemap-routes.json"
        ]
      }
    }
  ]
}

I've tried many configurations to avoid the server parsing the documents every cold start but didn't succed. I also tried keep ssr: true with target: static but didn't managed to make it work. And even if it worked, I doubt that would solve the problem.

Thanks!

0

There are 0 best solutions below