Is there a performance concern when using manual bootstrapping in AngularJS?

Please allow me to explain briefly before requesting your input on this particular matter.

Currently, I have a traditional AngularJS application where a specific div in my body contains the ng-app attribute and all scripts are placed at the bottom of the body.

Solution 1:

<body>
    <div ng-app="myApp">
       <!--remaining markup of the app will be here-->
    </div>

    <!--scripts located at the end of the body-->
    <script ...></script> <!--app.js/entry point--> 
    <script ...></script> <!--configs--> 
    <script ...></script> <!--services-->
    <script ...></script> <!--controllers-->
</body>

It is important to note that script order matters, hence the manual arrangement.

My question revolves around how Angular functions during page loading. I am curious whether the following alterations could result in performance issues:

  1. I removed the ng-app attribute
  2. I rearranged the scripts without any specific order.

Solution 2:

<body>
        <div> <!--No ng-app attribute included-->
           <!--mark-up continuation goes here-->
        </div>

        <!--manually bootstraping-->
    <script>
     angular.element(document).ready(function() {
        angular.bootstrap(document, ['myApp']);
    });
    </script>

        <!--non-ordered scripts at bottom of body-->
        <script ...></script> 
        <script ...></script> 
        <script ...></script>
        <script ...></script>
</body>

The primary objective behind this was to eliminate the need for manual file ordering and bootstrap the Angular app after (by adding ng-app manually upon document load).

Now, please take into consideration the following aspects:

  1. There is a possibility of numerous script files.
  2. All these scripts might also be consolidated into one file.

My aim is to comprehend if there are any performance challenges with either solution and which may be more advantageous.

Answer №1

There is no significant impact on performance (at least not one documented by Angular). The alternative solution provides a better way to bootstrap an Angular application, in my opinion.


What is the purpose of doing this?

Sometimes, pre-bootstrapping work needs to be done where synchronous scripts wouldn't suffice. This approach is necessary when using technologies like requireJS or webpack, providing more control over when the app actually starts functioning.

It is advisable to shift the bootstrapping process to the end of the file to avoid relying on the asynchronous nature of the ready function, which may result in it working even when called before all scripts have loaded.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Concealing columns in DataTables based on designated screen sizes

Issue I am facing a challenge with two DataTables — one with five columns and the other with four columns. My goal is to find a solution for hiding certain columns based on specific screen widths. Approaches I've Tested While resizing the browser ...

Explore the orders information with the Prestashop module

Hello I am trying to display the details of orders similar to the ones in history orders I have used the history.js but I am not able to get the page that displays the details of orders Below is some code snippet: {foreach from=$orders item=order name= ...

"Converting Json Key values from boolean and number types to string type: A step-by-step guide

I have a JSON object with keys of string, boolean, and number types. I need to convert the boolean and number key values to string type. For example: {"rent":2000,"isPaid":false} is valid JSON. I want to convert rent and isPaid to string type like this: {" ...

Hidden visibility of input field prevents the value from being posted

I have a dropdown menu containing numbers as options. When a user selects a number, I want to display an input box using jQuery based on their selection. However, the issue arises when I try to submit the values of these input boxes as they are not being s ...

Unlimited scrolling: Fetching additional data via an Ajax request?

I am working on setting up a table with infinite scroll functionality to showcase user information such as name, address, and email. To accomplish this, I began by importing the json-server package and creating an API endpoint using fakerjs in a separate f ...

Guide on setting up factories with pre-existing relationships in MIKRO-ORM

Hey there! I'm currently exploring how to set up a factory and establish relationships between models. For instance, I have a UserFactory that corresponds to the User entity which is connected to the userType table. However, in the factory, I'm ...

What is the method for substituting the 3rd product with an image in the product list on Perstashop?

As an example, on each category page only 9 products are displayed. I am interested in replacing the 3rd product with an image (no need for backend support, hardcoding is fine), and moving the original 3rd product to a new block. Is there a module availa ...

What could be the reason behind this button becoming completely ineffective after just one click?

Whenever I click the button (with class "add-book-btn"), I want to insert a new div (with class "book-card"). The code snippet below initially works when I click the button for the first time. However, afterwards something goes wrong an ...

As I go through the database, I notice that my div model functions correctly for the initial record but does not work for any subsequent ones

I came across a model on w3 schools that fits my requirements, but I am facing an issue where the model only works for the first result when looping through my database. It's likely related to the JavaScript code, but I lack experience in this area. C ...

What is the method for selecting a check box in AngularJS?

I am struggling with two lists (List 1 and List 2) of checkboxes that have three items in common. The issue I'm facing is that when I check an item in List 1, the corresponding item in List 2 also gets checked, which should not happen. I need to find ...

Which is better for creating contour graphs: JavaScript or PHP?

I need to create a scientific graph for a web application that displays temperature data based on time and depth coordinates. You can view an example here : I have time and depth coordinates, and I want to represent temperature using color in the graph, ...

What is the correct way to interpret the URL of attachments in messages?

I'm trying to create a feature where, when someone sends an image or a link of an image (like with Imgur), the attachment's URL gets logged in a specific channel. I attempted to achieve this using if(message.attachments.length > 0 || message. ...

Is there a way to extract a variable's value from the URL and distribute it to all links across the website, excluding those on the homepage?

Recently, I was attempting to achieve something similar to this concept how to retrieve variable values from the URL and pass them to all links on a website? However, I encountered an issue where simply visiting the homepage or any other page without the ...

Finding the host name of a client machine using Node.js

Is there anyone who can assist me in obtaining the client's machine name or host name for authentication on my website, which is operating internally within my company domain? I attempted the code below but received the server's host name instead ...

"An unknown date has been selected in the datepicker

I am encountering an issue with bootstrap-datepicker, and the error message I'm receiving is: Uncaught TypeError: Cannot read property 'split' of undefined Despite using the cdn from their official website, I believe I do not have an out ...

Tips for utilizing Sass and CSS Modules within create-react-app

I've been using FileName.module.scss to style my react elements like this: // Component styling with SCSS import React from "react"; import Aux from '../../hoc/Aux'; import classes from './Layout.module.scss'; const lay ...

Anticipated worth following the setTimeout function has been established

When trying to set the expected value in a setTimeout function, I encountered an issue. The two values I have are: const first = 0; const second = 0; However, this resulted in an error: "Uncauth TypeError: You provided 'undefined' where a strea ...

Troubleshooting issue: Angular not resolving controller dependency in nested route when used with requirejs

When the routes are multiple levels, such as http://www.example.com/profile/view, the RequireJS is failing to resolve dependencies properly. However, if the route is just http://www.example.com/view, the controller dependency is resolved correctly. Below ...

What is the best way to securely store JWT tokens in React JS in order to authenticate access to different backend routes within an app?

In my project, I am utilizing the JWT token for authentication and authorization purposes. Post-login, I need to store the token value in the frontend (React JS) to be able to send it to the server for validating various routes in Node.js based on differ ...

Pattern matching for ' ... '

I've been struggling to make a regular expression work properly: I need it to match anything that starts with __(' or __(" and ends with ') or ") I attempted using /__\(['"][^']*['"]\)/g and /__\([&apos ...