0

I have the following code in a for loop which combines 16 js files. What happens is that I want to lazy load these 16 files instead of doing it this way. Can someone tell me how to accomplish this. The reason I want to lazy load is because I have a file size limit that I do not want to exceed and I believe lazy load will prevent my file from exceeding a certain size threshold.

 for (var n = 1; n < 17; n++) {
            var trees = require('./code_files/' + n + '.js');
            for (var i = 0; i < trees.length; i++) {
                classes[trees[i](features)]++;
            }
mcfred
  • 1,183
  • 2
  • 29
  • 68
  • Where do you run this code? In the browser or Node.js? – str Sep 07 '20 at 10:55
  • Does this answer your question? [what is the right way to append all Js files using Jquery append](https://stackoverflow.com/questions/63724492/what-is-the-right-way-to-append-all-js-files-using-jquery-append) – Reyno Sep 07 '20 at 10:59
  • @Reyno, No it doesn't. I think I am looking for something with the webpack library. – mcfred Sep 07 '20 at 11:06
  • @str, in node.js – mcfred Sep 07 '20 at 11:18
  • What kind of file size limit do you have? It seems very unusual to have such a limit on the backend. And `require`ing a file on the backend does not change any file sizes anyway. – str Sep 07 '20 at 11:35
  • Looks like this is the answer you looking for: https://stackoverflow.com/questions/9132772/lazy-loading-in-node-js – tomer raitz Sep 07 '20 at 11:40

0 Answers0