Try ERPNext Buy Support Partners Foundation

Best way to deploy JavaScript code which is faster and more efficient?

Our company’s custom code is becoming bigger and bigger. One of my questions is that which is the best way to deploy JavaScript code which is faster and more efficient?

For example:
On Doctype Item I have made a lot of modifications. Let’s say, 10 different thing that are not linked with each other. Currently, I have created 10 .js files that starts with:

frappe.ui.form.on('Item', {
    refresh: function (frm, cdt, cdn) {
        [code goes here]
    }
})

Is it a better way if I just create 10 .js files with the functions in it and later on I put all the functions in one main .js file?

For example:

modification1.js

function modification1() {
    [do stuffs]
} 

modification2.js

function modification2() {
    [do stuffs]
} 

item_main.js

frappe.ui.form.on('Item', {
    refresh: function (frm, cdt, cdn) {
        modification1();
        modification1();
    }
})

or the way that I am doing right now is just fine?

In my experience, if all the code is not related, you probably want to do differents apps. If that’s not what you want for any reason, i like to have all in one js files, in other words, one js file with the functions AND the implementations.

Luckily I am using ES6. That means that I can split my functions and files. Import what I want in specific files and in the end I bundle my code with Webpack.
My issue here is not code and file structuring. I have no problem with that. My issue is code efficiency. I have not examined front end code and how it works that is why I am working.

That is why I am asking if it is faster and more efficient to import all the codes for specific DocType in one file, rather than calling Item DocType over and over again for each code.

I have noticed recently that the website is becoming a little bit slow for the back office users. At first I thought it was the back-end code, but after debugging and examining it, the code and SQL queries are just fine.

I misunderstood the question, sorry. I know nothing about js efficiency, but it looks more performant to call Item DocType just once.

Ni problem at all. Now that I am looking, I am making myself clear. My apologies.