Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Load only components and dependencies needed #882

Open
1 task done
anthonyhexium opened this issue Jan 1, 2024 · 5 comments
Open
1 task done

Load only components and dependencies needed #882

anthonyhexium opened this issue Jan 1, 2024 · 5 comments
Labels
enhancement [Issue][PR] New feature pending-author [Issue] Add Storyblok employee pending-triage [Issue] Add labels to describe it or prioritise it

Comments

@anthonyhexium
Copy link

anthonyhexium commented Jan 1, 2024

Description

Hi !

We just pushed in production a brand new website made with Storyblok and Next.js !

Everything is running good but performance is really important to us. We found out that all components part of the storyblokInit are called on all pages (even if we use dynamic).

The problem is that we use some heavy librairies (like uppy for uploading or codemirror to style code blocks).

For example, when we are one the homepage we still find code in the javascript download part of our contact form (which need uppy).

I am using nextjs 14 with app router !

Is there a way to improve this ?

Suggested solution or improvement

We should import only the javascript needed on the page. But I don't know if this comes from storyblok or nextjs.

Additional context

No response

Validations

@anthonyhexium anthonyhexium added enhancement [Issue][PR] New feature pending-author [Issue] Add Storyblok employee pending-triage [Issue] Add labels to describe it or prioritise it labels Jan 1, 2024
@arorachakit
Copy link
Contributor

Hey @anthonyhexium !
Thanks for letting us know your case. Yes we are aware that this can be an issue.
We got this reported as well as a solution from a community member a couple of months back. You can take a look at this - https://github.com/storyblok/storyblok-react?tab=readme-ov-file#3-adding-components-per-page

Using setComponents, you can load the components per page (or per route) however your prefer. But in this, the prerequisite is to know which components are going to be used in a specific route. This can improve the structure of your project a little. :)

cc - @fgiuliani

@anthonyhexium
Copy link
Author

@arorachakit thanks for your answer.

Well problem is that we use a [[...slug]] directory which build all our pages so I guess I cannot use this solution right ?

@arorachakit
Copy link
Contributor

Hey @anthonyhexium ! That is right, if you are rendering all routes with that, then you might not be able to use it this way.
We are aware of this issue, and it happens with every framework out there. But I am not sure how possibly we can have this implemented as of now. Because the frontend doesn't know which components are going to be there, along with what should be the order of the components.

I mean you can definitely see the components that are going to be needed from the API response, but it has to be implemented somehow in the frontend to only import those. StoryblokComponent just helps you to render those dynamically if they are registered in the init function or in the setComponents function. I am not exactly sure of how we can import the components dynamically, but an idea would be to see the story and the components required and then import only those in the file to register in the setComponents function.

cc - @fgiuliani

@fgiuliani
Copy link
Collaborator

Hey @anthonyhexium !

Maybe an approach could be creating separate React Components for the different types of pages you may have on your project, and calling the setComponents function from the inside of those React Components, setting the proper list for each one of them? 🤔

@pixelmultiplo
Copy link

This seems like a real deal-breaker.
With a decent sized website, the amount of components and the size of the bundle become huge fast.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement [Issue][PR] New feature pending-author [Issue] Add Storyblok employee pending-triage [Issue] Add labels to describe it or prioritise it
Projects
None yet
Development

No branches or pull requests

4 participants