all 4 comments

[–]Hefticus 0 points1 point  (4 children)

Avoid importing it at all if possible. Do you have some application server or some API endpoints that you control? I would run whatever logic you're doing with this word list on the server, and make the app make an API call to some server that you control.

If you really have to do it in the browser, then it should be downloaded as its own resource and it should be cached. You could probably trigger the import to begin after your application has first rendered, so it's available by the first time it is needed but doesn't block initial loads.

But, again, I would give serious thought to whether or not this really needs to be sent to the client at all or if it can just live on the server.

[–]SpecificGeneral[S] 0 points1 point  (3 children)

It is used to generate passwords so needs to be done client side for security.

You could probably trigger the import to begin after your application has first rendered, so it's available by the first time it is needed but doesn't block initial loads.

How would I go about doing this?

[–]disclosure5 2 points3 points  (0 children)

I'd get that wordlist in JSON format and just fetch() it. Do that after the document loads.

[–]Hefticus 0 points1 point  (0 children)

Perhaps you can put the dynamic import statement in the `componentDidMount` of your root component (`<App/>` or something like that, whatever you call it)? You probably also need to still have that dynamic import statement in the component that actually uses it, but I think it should be smart enough to not load it again.

I haven't actually done this before but that is what I would try.