storyblok-nuxt icon indicating copy to clipboard operation
storyblok-nuxt copied to clipboard

Is there a way to lazy load the storyblok client in nuxt?

Open hamsterbacke23 opened this issue 4 years ago • 6 comments

We don't want to add 110kb to our client in production just to make a few api calls, but it would be acceptable to dynamically lazy load it when required for editing.

We know we can call the api urls directly, but also don't want to loose the great user experience for our editors.

hamsterbacke23 avatar Apr 09 '20 14:04 hamsterbacke23

+1

chrschdev avatar Oct 09 '20 07:10 chrschdev

Hello :). By lazy you mean async? Or to have the choice of adding the bridge or api? Or more?

flozero avatar Jan 15 '21 01:01 flozero

I mean that only the minimal code is loaded for each user's usecase.

Let's say I build a JS bundle for my nuxt app for production. In that bundle there is ideally close to zero code from storyblok, I just want to call some APIs. Then an editor comes to the app, want's to edit a page. In that case I don't want to give him a separately built JS bundle because this requires extra maintenance. Instead, the app recognizes that the app now needs additional JS from storyblok to make editing possible. It "lazely" loads it at that moment and enables the cool live-editing UX we all love.

hamsterbacke23 avatar Jan 22 '21 11:01 hamsterbacke23

Ok, I think that's what I have understood.

thanks for clarifying :).

flozero avatar Jan 22 '21 11:01 flozero

Has anyone figured this out or is there even an officially recommended way nowadays?

klaemo avatar Sep 07 '21 07:09 klaemo

Hi are there any updates on this? Is it in the pipeline? @f3ltron

reinoldus avatar Sep 23 '21 07:09 reinoldus

Hi, @hamsterbacke23 thanks a lot for this issue, I was investigating a little bit the Nuxt docs for modules https://nuxt.com/docs/guide/going-further/modules/#async-modules and I don't see any reference to the possibility of lazyloading modules

What I do see is useLazyFetch which would help you achieve it without the SDK tho.

Fetching is done at https://github.com/storyblok/storyblok-js level, not by the vue or nuxt SDKs so probably this is something that you could request as a feature there if you are still interested,

Since sadly is not something we can do at this level, I will close the ticket, feel free to open it again if you still have more questions

alvarosabu avatar Feb 27 '23 09:02 alvarosabu

Hey thanks for the feedback. I think with the new Storyblok API it might be possible to lazyload editing js client-only, but need to look into it.

hamsterbacke23 avatar Feb 27 '23 09:02 hamsterbacke23