I’m wondering, is there a way to remove a module from the client after it’s been imported? Would there be any benefit in doing so?
I’m thinking in the context of, let’s say you import a text editor and 10 other things into the client. That could take up quite a bit of memory, especially on low end devices. Perhaps its better to get rid of them when possible.
cc module master @benjamn
After the payload has made it to the client, its already taken the “hit” it’s going to take. FMPOV I can’t see the benefit of removing it after that. I’d love to hear what others say.
i’ll support on @aadams response,
There is literally no real-life scenario where unloading js payload could profit to enough extend.
DOM, media unloading are sufficient and are handled by browsers pretty well.
I’d challenge that statement because it depends on the app and how its used.
If you look at Facebook website, sometimes you are in their Messenger section, other times you are in Newsfeed or Groups or some place else. All of these must be pretty big “modules”.
When you consider that people open it in like 20 tabs, and that not everyone has a high-end machine, it can all add up.
I’d say that it depends on code quality.
Things we mostly want to unload is code being executed. In case, static code doesn’t execute and therefore wastes too little resources to make it worth optimising. In React world, you typically able to control events and components quite well, and therefore have no unexpected behaviour or waste of resource.
I’m not sure of theoretically possible amount of code we would want to unload due to its size.
But browser can easily deal with massive amounts of data
have you ever seen http://devdocs.io/, it literally loads very, very large amount of data and text(and code that ain’t called are exactly objects and text) but you won’t have any trouble with most devices, unless the allowed memory is very limited.
So, I think, yeah - its possible to hack(browsers don’t provide us info, if device is low-spec or not), its possible to work around it, so fast clients won’t have issues of un-needed unloads, but it will all take time.
Does it worth it? I’m pretty sure it doesn’t
2-10 mb is very small amount, compared to resources reserved by DOM and media.
Even if your code grows as huge as 30mb+(why would you even do that) it would still impact on load and execution time much more than simply storing code. So yeah, you can unload code, but that’s very rare case.