Many back-end frameworks started to adopt this technique over the past years, most of them have some sort of URL redirect that points to a “index” file or a router that decides which actions should be executed and which files should be loaded instead of having a single file for each page or section. This kind of abstraction increases flexibility a lot since you can just keep adding new pages/sections/features without having to care about the code structure, it also reduce code duplication since you don’t need to create a new file for each new page…
Flash projects have a Main Class which is the entry-point for the application and also works as the root node where all the child elements are attached (similar to the body element of an HTML file) and it helps you keep the code flow organized since you are sure that your Main Class constructor is executed before any other code, programs get easier to understand since it follows a logic order.
HTML pages can have multiple script tags (and that is a good thing) but it causes many problems specially as websites starts to grow. Code can get very messy since you need global variables/objects to communicate across different files, it is harder to identify where the application initiates and which code gets executed first, having multiple requests also degrades performance – specially before `DOM Ready` since it blocks the HTML rendering. Another option is to create a single “Megazord” file which contains the whole code of your app, this tends to become unpractical for medium and large projects - the bigger the file the harder to read, understand and maintain it.
Having multiple entry-points makes the “code execution flow” harder to understand, you need to fully understand the application structure to be able to make changes without breaking things, the simple action of removing or re-ordering certain includes may break the whole application. You also have no idea of which files are required by all pages and which ones aren’t, your problems grows together with the complexity of your application leading to many headaches…
Single entry-point for the win!
Use RequireJS* and benefit from it’s awesome dependency management and build tool (that combines and compress files for deployment). Break your application into multiple small files/modules for better organization (try to keep each file under 200 lines), group functions by similarity/context and keep a single entry point for your app, you will probably notice a huge organization improvement on the first couple projects. As soon as you understand how an AMD module works you will see that global variables aren’t needed anymore.
* other script loaders may be a good option as well, I’ve been using RequireJS since it is popular, have an active community, it’s “battle-tested” and AMD modules are awesome!
PS: If you need a powerful and flexible library for URL mapping/routing check Crossroads.js, my latest open-source project.