javascripttypescriptnext.jsmainbundle

Remove a js array from the Next js main bundle


There is a very large hard-coded array in my Next js application and I'm importing it in a few other places to use. Because of that, it has been included in the Next js main bundle. Since it is a very large file, I would like to remove it from the main bundle. Even though for components we can use next/dynamic to do this, for an array I couldn't find any method to resolve this. Could anyone help me with this one, please? Any kind of help is greatly appreciated.

main bundle content:- enter image description here


Solution

  • You can create an API route and call it when needed, that's the benefit of Next JS, very easy to do that.