3

I'm currently building a new version of my company's site and we choose Nuxt to do it. For my coworkers, it is important to keep the ability to manage the content so we are keeping Wordpress as a CMS. Then we generate the JSON with Wordpress's REST API and we inject it in the webapp, basically it is just an headless Wordpress.

Long story short, I'm currently trying to figure out how to host this monstruosity, and I'm facing a big issue: the home page takes 15sec to load. Fortunetally, the rest of the app is not so bad in term of first load. May you take a look at my Google lighthouse score.. Yes I'm ashamed.

My incredible app optimization

please help me

So maybe you are wondering, how this poor man created this ? Let me tell you what I use to do that :

  • TailwindCSS (with JIT)
  • Nuxt@2.15.3
  • NuxtI18n (with BIG JSON files -> total 12,6 Mo)
  • The app is hosted on Heroku

My nuxt.config file :

export default {
  devServer: {
    historyApiFallback: true
  },
  
  tailwindcss: {
    configPath: '~/config/tailwind.config.js',
    jit: true
  },

  // Global CSS: https://go.nuxtjs.dev/config-css
  css: [
  ],

  // Plugins to run before rendering page: https://go.nuxtjs.dev/config-plugins
  plugins: [
    { src: '~/plugins/main.js' },
    { src: '~/plugins/vuex-persist', ssr: false },
    { src: './plugins/vue-awesome-swiper.js', ssr: false },
    { src: '~/plugins/fullpage.js', mode: 'client' },
    { src: '~/plugins/aos.client.js', ssr: false},
    { src: '~plugins/v-calendar.js', ssr: false }
  ],

  // Auto import components: https://go.nuxtjs.dev/config-components
  components: false,

  buildOptimisations: {
    profile: process.env.NODE_ENV === 'development' ? 'risky' : 'experimental'
  },

  // Modules for dev and build (recommended): https://go.nuxtjs.dev/config-modules
  buildModules: [
    // https://go.nuxtjs.dev/tailwindcss
    '@nuxtjs/tailwindcss',
    '@nuxtjs/dotenv',
    [
      'nuxt-i18n',
      {
        locales: [
          {
             code: 'en',
             name: 'English',
             file: 'en-EN.js',
             flagImg: 'english_flag.png'
          },
          {
             code: 'fr',
             name: 'Français',
             file: 'fr-FR.js',
             flagImg: 'french_flag.png'
          },
          {
            code: 'de',
            name: 'Deutsch',
            file: 'de-DE.js',
            flagImg: 'german_flag.png'
         },
        ],
        lazy: true,
        langDir: 'lang/',
        defaultLocale: 'fr',
        parsePages: true,
        vueI18n: {
          fallbackLocale: 'fr',
        },
        vuex: {
          moduleName: 'i18n',
        },
        seo: false,
        detectBrowserLanguage: false,
      }
    ]
  ],

  // Modules: https://go.nuxtjs.dev/config-modules
  modules: [
    // https://go.nuxtjs.dev/axios
    '@nuxtjs/axios',
    // https://go.nuxtjs.dev/pwa
    '@nuxtjs/pwa',
    'nuxt-leaflet',
    'vue-social-sharing/nuxt',
    '@nuxtjs/composition-api/module',
    '@nuxtjs/dayjs'
  ],

  // Axios module configuration: https://go.nuxtjs.dev/config-axios
  axios: {
    proxy: true
  },

  // PWA module configuration: https://go.nuxtjs.dev/pwa
  pwa: {
    manifest: {
      lang: 'fr'
    }
  },

  // Build Configuration: https://go.nuxtjs.dev/config-build
  build: {
    extend(config, ctx) {
      config.node = {
        fs: "empty"
      }
    },
    parallel: true,
    cache: true,
    hardSource: true,
    html: {
      minify: {
        collapseBooleanAttributes: true,
        decodeEntities: true,
        minifyCSS: true,
        minifyJS: true,
        processConditionalComments: true,
        removeEmptyAttributes: true,
        removeRedundantAttributes: true,
        trimCustomFragments: true,
        useShortDoctype: true,
        removeComments: true,
        preserveLineBreaks: false,
        collapseWhitespace: true
      }
    },
    loaders:  {
      vue: {
        prettify: false
      }
    },
    transpile: ['vee-validate'],
    postcss: {
      plugins: {
        "postcss-custom-properties": true
      },
    },
    extractCSS: false
  },
}

I can't figure out why this page take so much time to load, I split the page in several components, I try to load the minimum amount of JSON data on these files, I use vue-lazyhydrate, try to load components asynchronously: nothing works. I know my code is far from perfect, but still.. 15 seconds is a lot.

kissu
  • 40,416
  • 14
  • 65
  • 133
Patrick
  • 31
  • 2
  • Alright, first step is as you thought: checking this i18n module, maybe lazy-load it. But firstly, try to just remove it. Also, since it's a server response time, maybe try to `yarn build && yarn start` it locally to see how it behaves. Lastly, checking the network tab could also be a good starting point. – kissu Sep 22 '21 at 17:21
  • Also, are you on a paid Dyno on Heroku? I'm not sure that the free one is really fast. Lastly, `mode: 'client'` is the same as `ssr: false`, just that `ssr: false` is deprecated so don't use this one please. – kissu Sep 22 '21 at 17:24
  • 2
    The i18n module is already lazy-load, I also tried to set skipNuxtState on true. But you are probably right, it must be a problem with i18n. The behavior is the same locally unfortunatelly. Yes we are on paid, and I've change mode:client to srr: false thank you ! – Patrick Sep 23 '21 at 09:04

1 Answers1

0

I agree with you that nuxt rendering takes too long time, but this problem is only in nuxt2 and you can update your nuxt to the new nuxt3 and this problem will be solved. create nuxt3 app.

  • 1
    A Nuxt 3 migration is not enough by itself tbh. Can help but that will not bump the core web vitals with just this. – kissu Mar 19 '23 at 10:21