Global object for project

Asked

Viewed 49 times

3

I am doubtful, if this way would be a very "ugly" method of making:

https://gist.github.com/anonymous/6df36cc016a10bed0d66

In this case, an object called "Ecommerce" was defined, and I am assigning to it the functionalities.

Another item you would like to know other ways, or if it is correct, is loading plugins in the same file.

  • Helder, this code is really big. I want to help but I’m not going to look at all this code, I don’t have time. You can clarify the question and add a schematic of the code?

  • My question is whether, define this object "Ecommerce" and assign all the functionalities to it is correct to do. The other item refers to plugins that are loaded at the end of the file, it would be better to create a "plugins.js" for example, instead of loading them in the same file? In performance issue, it would be better 1 file only right, because it is a request less.

1 answer

2


Creating an object with all the methods you need is a very good idea. It’s called creating a name space. This avoids conflicts in the case of declaring variables or functions with names that may already exist.

Regarding merging several codes in the same file depends a little. If the overall script is not too large it is good to have it in the same file to have everything organized. If it is large it may be better from a performance point of view to have several parallel requests running simultaneously, this makes the page load faster despite being multiple requests.

The code that doesn’t need to be on <head> (code that is not needed before the user interacts) can load after (outside the head) and this also makes the page load faster.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.