content icon indicating copy to clipboard operation
content copied to clipboard

[Performance] Improve Nuxt content performances

Open Hebilicious opened this issue 1 year ago • 30 comments

Is your feature request related to a problem? Please describe

Whenever I see a website built with Nuxt content, I notice that the page transitions are noticeably slow. You can use Nuxt UI Labs or the Nuxt docs as an example. After a refresh, on each page navigation, there's a server delay that can take up to 300ms for me before the page is being displayed, giving the feeling of a laggy application.

Some resources can even take longer (when there's shiki loaded on the page).

Example : NuxtContent lag

Describe the solution you'd like

As these website are mostly static, they should be very performant and there shouldn't be a visible delay between page transitions.

Describe alternatives you've considered

I don't have an alternative, as Nuxt Content has many great features. For markdown only, I use Vitepress and I made a POC version for nuxt : https://github.com/Hebilicious/nuxtpress

Additional context

Note that this apply on the latest versions of all browsers in incognito mode. This could be also due to the fact that there's no Caching/CDN for the JSON.

Hebilicious avatar Jun 13 '23 08:06 Hebilicious

@Hebilicious Thank you for writing this issue. i’ve been dealing with this problem for a while now without understanding why. i use both markdown and json and my static site is much slower than I would like. I guess it was the lack of caching on JSON. Thanks.

ryoheiw avatar Jun 20 '23 17:06 ryoheiw

@Hebilicious Thank you for writing this issue. i’ve been dealing with this problem for a while now without understanding why. i use both markdown and json and my static site is much slower than I would like. I guess it was the lack of caching on JSON. Thanks.

Could you share what you've done to cache it ? I think it could be useful to others.

Hebilicious avatar Jun 20 '23 18:06 Hebilicious

@Hebilicious I do not have a solution to this problem. The comment above was thanking you for letting me understand the reason for its slowness. I will add something here if I find a solution though.

ryoheiw avatar Jun 21 '23 00:06 ryoheiw

I totally agree.

I believe that we need to prefetch the components used in document-driven mode. By default Nuxt will prefetch the payload required - which will include an AST of the file. We also expose a prefetchComponents utility that Nuxt Content could use to prefetch the components used in this AST.

Let me know if someone fancies tackling this - I'd be happy to help.

danielroe avatar Jun 23 '23 12:06 danielroe

Great to hear that you're looking into this. What I would personally want from this module is to match vitepress performance for static content. I'm thinking that an approach that leverages service worker caching and SWR out of the box could fit this JSON payload pattern during the client side routing. Also I wonder if we could leverage nuxt server components in some ways to increase the performances even further ?

Hebilicious avatar Jun 24 '23 02:06 Hebilicious

I've also noticed this disparity between VuePress and Nuxt / Nuxt Content (and I think we spoke about this before Daniel).

In VuePress, a pregenerated site navigates to new pages instantly. In Nuxt Content, not only does the page take time to load, but I also find the content can take time to display.

I don't know if this is my setup or just how NC works, but it's very noticeable.

As a comparison:

  • https://davestewart.co.uk (VP)
  • https://controlspace.app/guide (NC)

davestewart avatar Jun 24 '23 10:06 davestewart

If you're interested, I just opened a PR (https://github.com/nuxt/content/pull/2118) and deployed a patched version of nuxt.com to test it: https://nuxt-website-idcnshvbq-nuxt-js.vercel.app.

I expect there are issues, but would value thoughts + testing.

danielroe avatar Jun 24 '23 13:06 danielroe

I can see a definite improvement, it's inconsistent and sometimes there's still s jarring delay, but some of the page transitions felt snappier.

Hebilicious avatar Jun 24 '23 13:06 Hebilicious

Do you have an example route -> route transition that is not improved?

danielroe avatar Jun 24 '23 16:06 danielroe

Do you have an example route -> route transition that is not improved?

Unfortunately I can't consistently reproduce it, most of the times, the green loading animation at the top doesn't display and the page transition is snappy, but sometimes it still displays and there's a visible delay (relatively short). It does happen a little bit more on mobile than on desktop.

Could this be happening because of some ISR/SWR at the server level ?

Hebilicious avatar Jun 25 '23 11:06 Hebilicious

Just to confirm, you're navigating only between pages in the /docs subpath, right?

danielroe avatar Jun 25 '23 11:06 danielroe

Just to confirm, you're navigating only between pages in the /docs subpath, right?

Yes. It's easier to reproduce in incognito mode and to spot by looking at the Title in the tabs bar. However it's still a very big improvement compared to the old version.

Hebilicious avatar Jun 25 '23 15:06 Hebilicious

Navigating between document-driven pages is faster. Here a comparison:

Without perf/speed-up

nuxt3-content-without-perf-speedup

With perf/speed-up

packages.json

  "pnpm": {
    "overrides": {
      "@nuxt/content": "github:@nuxt/content#perf/speed-up"
    }
  }
nuxt3-content-with-perf-speedup

Navigating to a document-driven folder from a normal page still entails a noticeable delay (hosted on Vercel).

oripka avatar Jun 25 '23 18:06 oripka

I deployed today nitro docs using the cloudflare-pages-static preset : https://nitro-docs.pages.dev/

The jarring transitions are still there when you navigate to a page for the first time. After that, alternating navigation between 2 pages is relatively snappy.

Hebilicious avatar Jul 14 '23 04:07 Hebilicious

@Hebilicious Until today, the fix was not released. But now you can try in v2.7.1.

danielroe avatar Jul 19 '23 13:07 danielroe

Just saying, Nuxt and Vue are really have my heart but....Nuxt performance stats gives a lil pain in my heart to see not going with nextjs with react , I am not gonna deal with self killing every update lol.

Yea I wish performance gets improved and best wishes to all of u who contributing here

Someday I will too

vis2021t avatar Aug 07 '23 02:08 vis2021t

I have modified the deployment command, and the webpage loading speed has improved significantly.

image

fzdwx avatar Aug 07 '23 06:08 fzdwx

I have modified the deployment command, and the webpage loading speed has improved significantly.

image

Nice, how much improvement did u saw? Any stats? Just to be known with?

vis2021t avatar Aug 07 '23 19:08 vis2021t

I have modified the deployment command, and the webpage loading speed has improved significantly.

image

Nice, how much improvement did u saw? Any stats? Just to be known with?

https://fzdwx.vercel.app/

It's now almost a second in, and it takes 300 ms to 1200 ms to load a page before I can modify the build command.

fzdwx avatar Aug 07 '23 21:08 fzdwx

I have modified the deployment command, and the webpage loading speed has improved significantly. image

Nice, how much improvement did u saw? Any stats? Just to be known with?

https://fzdwx.vercel.app/

It's now almost a second in, and it takes 300 ms to 1200 ms to load a page before I can modify the build command.

Do u feel like in further update nuxt will get better in this performance? I have heard about next performing better aa framework but they didn't make me feel comfortable as a dev.

vis2021t avatar Aug 08 '23 02:08 vis2021t

We will work on it and fix those performance issues.

atinux avatar Aug 08 '23 08:08 atinux

I have modified the deployment command, and the webpage loading speed has improved significantly. image

Nice, how much improvement did u saw? Any stats? Just to be known with?

fzdwx.vercel.app It's now almost a second in, and it takes 300 ms to 1200 ms to load a page before I can modify the build command.

Do u feel like in further update nuxt will get better in this performance? I have heard about next performing better aa framework but they didn't make me feel comfortable as a dev.

Just to be clear, this is an issue with this module, not with Nuxt itself.

Hebilicious avatar Aug 08 '23 11:08 Hebilicious

Any update on this?

oripka avatar Sep 22 '23 19:09 oripka

I started building my blog using nuxt and nuxt/content but the speed to load an article is way too low. I'll just use the right tool for the right job by switching my blog to Astro. Screenshot 2023-10-30 at 21 08 30

matschik avatar Oct 30 '23 12:10 matschik

@matschik so far we suggest to statically generate your website using nuxt generate command.

We are at the moment experimenting compiling Markdown to Vue files similar to VitePress

atinux avatar Oct 31 '23 07:10 atinux

Nice, nuxi generate is great, but SSG doesn’t work if the content should be behind a middleware for authorization. Glad that there is experiments to fix the issue. I didn’t find the experimental branch, is it private for now?

I am running nuxt/content on a production website with a lot of markdown content. It works well, I just have the issue of performance when using SSR.

oripka avatar Oct 31 '23 14:10 oripka

I'm leaving a comment, so I can follow the update 👀 it will really be great for SEO performance

My hint is in SSG mode it should just prefetch the content during "nuxi generate" so it doesn't need to call the server on client side (queryContent), https://quasar.dev/quasar-cli-vite/prefetch-feature could be a good hint

strife-cloud avatar Nov 11 '23 19:11 strife-cloud

With the latest commits that implement the Nitro Cache API. I was now able to do this in order to cache the API calls. Seems to work well.

nuxt.config.ts

  nitro: {
    storage: {
      cache: {
        driver : 'vercelKV',
        url: "https://xxxxx.vercel-storage.com",
        token: xxxx',
        ttl: 3600,
      }
    }
  },

oripka avatar Dec 19 '23 20:12 oripka

After talking to @farnabaz we will also add caching for Nuxt Content API routes, for deployment to Netlify or Vercel with SSR, this should improve a lot the performance, stay tuned to the next relase.

atinux avatar Dec 20 '23 14:12 atinux

After enabling the caching I noticed that in dev mode I need to have the browser dev tools open in order to get fresh content. Not sure if this is a bug.

Also I did not test it yet but I assume all of this still respects the server API middleware using the cachedEventHandler as well as the ISR route rule approach. Is this correct?

oripka avatar Dec 20 '23 16:12 oripka