0

In PHP I can use include_once("phat/library") to include if has not yet a library or file to improve performance not re including it. Something like that in vue or react or another child of javascript ?

Yes, exist and in this link you can see it or not, the new javascript frameworks or libraries dont care performace

  • Have you read these materials before? https://stackoverflow.com/questions/36564901/in-the-import-syntax-of-es6-how-is-a-module-evaluated-exactly and https://stackoverflow.com/questions/8958097/is-there-a-way-to-require-a-js-file-only-once-in-nodejs – Remicaster Nov 05 '22 at 14:52
  • I'm using import in vue2 spa code, but the chunks are 2/3 of spa size. see it [link] https://drive.google.com/file/d/1yBajjZcAAVC6b6Y4j6P07zxBm6c-VuN0/view?usp=share_link because i want minimize imports like include_once to reduce size of chunks, how I can do it ? – sentadoensilla Nov 05 '22 at 15:47

1 Answers1

0

There is no need for import_once because as Remicaster's links explain, imported modules are cached during first evaluation so that multiple imports of the same module return the exact same object. Your bundle analysis shows multiple bn.js modules because bn.js is a dependency to other modules and those other modules are very likely all using different versions of bn.js.

What you can try to do is add an override in your package.json to force only one install of bn.js for all your dependencies to use, though there is no guarantee that this won't break dependencies that rely on bn.js being a specific version.

yoduh
  • 7,074
  • 2
  • 11
  • 21