The Lazy component prefix and when to use it - Nuxt Performance in Depth

Поділитися
Вставка
  • Опубліковано 25 лип 2024
  • 🤯 Nuxt provides amazing auto-import capabilities for composables, utils and also components out of the box. But besides auto-importing them, it also provides a "Lazy" version of it. In the second video of the Nuxt Performance in Depth series, we have a look at the lazy prefix, what it does and when to use it to achieve sweet performance gains!
    Key points:
    🧠 What is the `Lazy` prefix and how is it implemented
    ✅ What does it do and when to use it
    🔍 Examples for usage and overusage
    Links:
    🔗 Nuxt Lazy Transform Plugin: github.com/nuxt/nuxt/blob/mai...
    🔗 Demo application: github.com/manniL/alexander-l...
    🔗 Async components: vuejs.org/guide/components/as...
    Don't forget to hit that "Subscribe" button, ring the notification bell and give a thumbs up!
    🌐 Connect further:
    Website: www.lichter.io
    Twitter/X: / thealexlichter
    Twitch: / thealexlichter
    Chapters:
    00:00 Intro
    00:50 Demo app overview
    01:15 What is the lazy prefix
    03:24 Which problem lazy solves
    04:58 Using the lazy component prefix
    06:16 Overusing it and why you shouldn't
    07:42 TL;DR and Summary
    #NuxtPerformanceInDepth #Performance #nuxt3 #lazy #async #nuxtjs #webdevelopment #frontend #frontenddeveloper
  • Наука та технологія

КОМЕНТАРІ • 54

  • @TheAlexLichter
    @TheAlexLichter  7 місяців тому +3

    Did you use the `Lazy` prefix so far?

    • @RIT_Edition
      @RIT_Edition 7 місяців тому +1

      Yes

    • @moe8055
      @moe8055 7 місяців тому +1

      yeah and only on my Footer and since then i sometimes get a strange error telling me failed to load module. But only if you hard reload the page several times. It gets displayed and is hydrated properly tho

    • @TheAlexLichter
      @TheAlexLichter  7 місяців тому

      @@moe8055 Weird. That should work always. Maybe because of redeploys?

    • @jurarexx
      @jurarexx 7 місяців тому

      @@moe8055 did you try to encapsulate your component with ?

  • @fedvvvv
    @fedvvvv 7 місяців тому +4

    Fantastic. I haven't looked into performance enhancements yet but I'll start using Lazy Loading for some tabbed components and my modals. This is great!

  • @Andrey-il8rh
    @Andrey-il8rh 7 місяців тому +2

    It would be so cool if you would make a collab course on Nuxt 3 with Maximilian Schwarzmüller from Academind, it would be like the best course in the world on Nuxt! You both share so practical and easy way of telling about all of those concepts which is so rare these days 👍

    • @TheAlexLichter
      @TheAlexLichter  7 місяців тому +1

      Interesting idea! Nothing is impossible 👀
      But being mentioned in a row with Max is already on honor 🙏

  • @riyad-appscode
    @riyad-appscode 7 місяців тому +1

    Awesome video. Thanks a lot 👍

  • @thejurex87
    @thejurex87 7 місяців тому +1

    Another great video. 👍

  • @wellingtoncapoia
    @wellingtoncapoia 7 місяців тому +1

    anxiously waiting

  • @ikhsan2652
    @ikhsan2652 4 дні тому

    love the video, thankyouu!!

  • @abhinavadarsh7150
    @abhinavadarsh7150 6 місяців тому +1

    Nice video. Subscribed ❤

  • @jurarexx
    @jurarexx 7 місяців тому +1

    very useful informations

  • @jahiddev
    @jahiddev 7 місяців тому +1

    🙌

  • @виртуоз_ру
    @виртуоз_ру 7 місяців тому +1

    Лучший 👍

  • @jydro
    @jydro 7 місяців тому +1

    Thanks for showing the source code! We're lazy loading some below the fold content, but it's different for mobile and desktop.

    • @TheAlexLichter
      @TheAlexLichter  7 місяців тому

      Yeah, that's the tricky part. If in doubt, rather lazy-load less than penalizing a larger percentage of users.

  • @zuko655
    @zuko655 7 місяців тому +1

    Thank you for covering features which are perhaps a bit more obscure or not well documented

  • @ivangorobec2803
    @ivangorobec2803 7 місяців тому

    Thank you, man! That`s very helpfull. Can you please tell about chunk splitting with modern nuxt in future videos?

    • @TheAlexLichter
      @TheAlexLichter  7 місяців тому

      You are welcome!
      What exactly you'd want to know about chunk splitting? How they are split by default and how to customize?

  • @cupritchanel5139
    @cupritchanel5139 7 місяців тому +1

    Terimakasih sharingnya kak salam sukses

  • @matanon8454
    @matanon8454 7 місяців тому +1

    🙏

  • @ragura
    @ragura 7 місяців тому +1

    Thanks for the explanation. Is there room in the series for a deep dive into a combination of cached server routes, local caching (useFetch keys like in your other video) and optimistic UI changes that update the local state and local cache accordingly while invalidating the server's cache after a change is made? I've been hitting this issue in my project where a large list is loaded and small changes can be made to it with post requests, but refreshing all the data just for this small change to be reflected in the UI seems like overkill.

    • @kissu_io
      @kissu_io 7 місяців тому +2

      Optimistic UI is quite nice (discovered it with Apollo) but it can also be quite tricky for a small amount of benefits. 😅

    • @ragura
      @ragura 7 місяців тому +1

      I agree, but it's an important UX factor when the refresh load is high. Back in the Vue 2 days I used to handle this with Vuex, which wasn't fun to work with but it got the job done. I think mutations through 'useNuxtData' is what can be used to streamline this.@@kissu_io

    • @TheAlexLichter
      @TheAlexLichter  7 місяців тому

      Great idea. I might cover that in a stream in a future because it might be a bit long for a single video. But let's see, maybe I can shrink it down 😊
      In the meantime, you might want to check nuxt.com/docs/api/composables/use-nuxt-data#optimistic-updates

  • @blokche_dev
    @blokche_dev 7 місяців тому +1

    Interesting! It would be much more useful with directives for placeholder (and loading and error states) as Angular introduced in the latest version.
    Vue lets you define AsyncComponent with loading state at its core but Angular defered views are really powerfull I think. No extra step with lazy declarations.

    • @TheAlexLichter
      @TheAlexLichter  7 місяців тому +1

      Technically this is possible in Vue too via defineAsyncComponent as you said (loading/error state), but I agree, a more declarative way would be interesting to see.
      With regards to hydration though, that is also something coming - See github.com/nuxt/nuxt/issues/24242

    • @blokche_dev
      @blokche_dev 7 місяців тому +1

      @@TheAlexLichter Oh interesting! Thanks.

  • @youhan96
    @youhan96 4 місяці тому

    Is there a fallback while the js for the Lazy component is being downloaded? What happens if the chunk load results in error?

    • @TheAlexLichter
      @TheAlexLichter  4 місяці тому

      You can define a fallback via a named fallback slot, yes 👌
      If any chunk load fails, nuxt will usually reload

  • @milos018
    @milos018 7 місяців тому +1

    I use Lazy almost by default for any Dialog/modal elements as they are not sure to be used in the app, therefore not needed to be loaded... There are other use-cases of course, but this would be the default

    • @TheAlexLichter
      @TheAlexLichter  7 місяців тому

      Yes, that's almost a no-brainer (as long as a possible delay is justifiable when the user clicks on the modal/dialog)

  • @randomtimessomehow
    @randomtimessomehow 4 місяці тому

    I have a question: Do Lazy components automatically effect their child components?
    For example, is this the correct way to do it: or like this:

    • @TheAlexLichter
      @TheAlexLichter  4 місяці тому +1

      It depends. If the component is passed as slot, then you'd need the prefix. If it is already part of the parent, you can omit it.

    • @randomtimessomehow
      @randomtimessomehow 4 місяці тому

      Thank you! I appreciate it :)@@TheAlexLichter

  • @tolgabeyazoglu536
    @tolgabeyazoglu536 7 місяців тому +1

    My understanding is that too much lazy loading is harmful and we should not lazy load components like the navbar footer.

    • @TheAlexLichter
      @TheAlexLichter  7 місяців тому

      Yes and no.
      ✔ Correct is: Too much lazy-loading is harmful. Also lazy-loading content *above the fold* is not good.
      When it comes to the Footer, I'd say you *can* lazy-load it if it is below the fold, so the user won't see or need it straight away. That's most common for most pages (without a sticky footer).

    • @tolgabeyazoglu536
      @tolgabeyazoglu536 7 місяців тому +1

      thank you for the answer@@TheAlexLichter

  • @freekeys
    @freekeys Місяць тому

    Still don't know where to use in real life application, it would be better if you show some websites that has it, for better visual understanding

    • @TheAlexLichter
      @TheAlexLichter  Місяць тому

      I might do that, thank you for the suggestion 🙏🏻

    • @freekeys
      @freekeys Місяць тому

      @@TheAlexLichter Thank you :)